Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """T08."""
- def alarm_clock(day: int, vacation: bool) -> str:
- """
- Return what time the alarm clock should be set.
- Given a day of the week encoded as 0=Mon, 1=Tue, ... 5=Sat, 6=Sun
- and a boolean indicating if we are on vacation,
- return a string of the form "08:00" indicating when the alarm clock should ring.
- Weekdays, the alarm should be "08:00" and on the weekend it should be "10:00".
- Unless we are on vacation -- then on weekdays it should be "10:00" and weekends it should be "off".
- alarm_clock(1, False) # -> '08:00'
- alarm_clock(3, True) # -> '10:00'
- alarm_clock(6, False) # -> '10:00'
- :param day: Day of week.
- :param vacation: Whether it is vacation.
- :return: String when to set alarm clock.
- """
- if day <= 4 and vacation is False:
- return "08:00"
- if day >= 5 and vacation is False:
- return "10:00"
- if day <= 4 and vacation is True:
- return "10:00"
- if day >= 5 and vacation is True:
- return "off"
- def keep_if_first_two_symbols_same(stringys: list) -> list:
- """
- Return list of strings where two first symbols of the element are the same.
- keep_if_first_two_symbols_same(["a", "bb", "bbbccc"]) # -> ['bb', 'bbbccc']
- keep_if_first_two_symbols_same(["mmem", "memm"]) # -> ['mmem']
- keep_if_first_two_symbols_same(["a", "a"]). # -> []
- :param stringys: List of strings.
- :return: Filtered list.
- """
- return [x for x in stringys if len(x) > 1 and x[0] == x[1]]
- def middle_chars(s: str) -> str:
- """Return two chars in the middle of string.
- The length of the string is an even number.
- middle_chars("abcd") # -> "bc"
- middle_chars("bc") # -> "bc"
- middle_chars("aabbcc") # -> "bb"
- middle_chars("") # -> ""
- """
- return s[(len(s) - 1) // 2:(len(s) + 2) // 2]
- def remove_nth_symbol(s, n) -> str:
- """
- Return a new string where n-th symbol is removed.
- If the n is outside of the string, return original string.
- If n is 1, the first symbol is removed etc.
- remove_nth_symbol("tere", 1) # -> "ere"
- remove_nth_symbol("tere", 3) # -> "tee"
- remove_nth_symbol("tere", 5) # -> "tere"
- :param s: Input string.
- :param n: Which element to remove.
- :return: String where n-th symbol is removed.
- """
- if n <= 0:
- return s
- else:
- return s[:n - 1] + s[n:]
- def in1to10(n: int, outside_mode: bool) -> bool:
- """d."""
- if outside_mode is False and 10 >= n >= 1:
- return True
- if outside_mode is False and 10 <= n >= 1:
- return False
- if outside_mode is True and n <= 1 or n >= 10:
- return True
- else:
- return False
- def love6(a: int, b: int) -> bool:
- """
- Given two int values, a and b, return True if either one is 6. Or if their sum or difference is 6.
- love6(6, 1) # -> True
- love6(3, 3) # -> True
- love6(2, 3) # -> False
- """
- if a == 6 or b == 6:
- return True
- elif a + b == 6:
- return True
- elif a - b == 6 or b - a == 6:
- return True
- else:
- return False
- def addition_and_subtraction(stringy: str) -> int:
- """
- Return the value of equation.
- The equation only consists of plus (+), minus (-) and digits (0-9).
- There are no 2 consecutive operands. In the end, there is no operand.
- In the beginning, both "+" and "-" are acceptable.
- "1+2" # -> 3
- "-1+21" # -> 20
- "+1-1" # -> 0
- :param stringy: Equation.
- :return: The result of equation.
- """
- if stringy == "":
- return 0
- return eval(stringy)
- def equalizer(unequal: list) -> list:
- """
- Equalize numbers between bigger or smaller numbers.
- [1, 4, 1] # -> [1, 3, 1]
- [1, 2] # -> [1, 2]
- [1, 4, 1, 0, 2] # -> [1, 3, 1, 1, 2]
- :param unequal: Unequalized list.
- :return: Equalized list.
- """
- for i in range(1, len(unequal) - 1):
- number = unequal[i]
- if unequal[i - 1] < number > unequal[i + 1]:
- unequal[i] -= 1
- elif unequal[i - 1] > number < unequal[i + 1]:
- unequal[i] += 1
- return unequal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement