Quiz - 6

Develop the function sleep that takes two parameters, weekday and holiday, both parameters take boolean values, meaning they can be either True or False. The function acts as follows: you can sleep when it’s a holiday or when it’s not a weekday. sleep will return True or False whether or not you will sleep.

Examples:
sleep(False, False) -> True
sleep(True, False) -> False

Develop the function students_in_trouble that takes two parameters, a_smiling and b_smiling. a and b represent two students. a_smiling and b_smiling indicate if a and b are smiling. When both are smiling or both are not smiling we have trouble. students_in_trouble should return True when there is trouble. Otherwise, it will return False.

Examples:
students_in_trouble(True, True) -> True
students_in_trouble(False, True) -> False

Develop the function double_sum that takes two parameters, a and b. Both are integers. The function should return the sum of a and b. However, if the numbers are equal, it returns twice the sum.

Examples:
double_sum(1, 2) -> 3
double_sum(2, 2) -> 8

Develop the function absolute_difference_21 that takes a parameter, n, and returns the absolute difference between n and 21 only if n is less than or equal to 21. If it is greater, then it returns twice the absolute difference between the number and 21. Remember: abs(x) returns the absolute value of x.

Examples:
absolute_difference_21(19) -> 2
absolute_difference_21(25) -> 8

Develop the function parrot_trouble that takes two parameters, talking, which can be True or False, and hour, which takes a value between 0 and 23. We have a parrot, and there is trouble if the parrot is talking before 7 hours or after 20 hours. Return True if there are problems or False if there are not.

Examples:
parrot_trouble(True, 6) -> True
parrot_trouble(True, 20) -> False

Develop the function makes10 that takes two parameters, a and b. Returns True if one of the parameters is 10, or if the sum of both is 10. Otherwise, it returns False.

Examples:
makes10(9,10) -> True
makes10(1,9) -> True
makes10(8,3) -> False

Develop the function near_hundred that takes n as a parameter, which is an integer. Returns True if the absolute difference between n and 100 or n and 200 is less than or equal to 10.

Examples:
near_hundred(93) -> True
near_hundred(90) -> True
near_hundred(89) -> False
near_hundred(210) -> True
near_hundred(211) -> False

Develop the function remover_iesimo that receives a non-empty string s and a positive integer i, and returns the original string without the i-th character.

Examples:
remover_iesimo("Hello", 1) -> "ello"
remover_iesimo("Hi", 2) -> "H"
remover_iesimo("PyZombiess", 10) -> "PyZombies"

Develop the function intercambiar that takes s as a parameter, representing a string. If s has a length of 1 or less, the same string is returned. Otherwise, the first and last letter of s are exchanged.

Examples:
intercambiar("codigo") -> "oodigc"
intercambiar("a") -> "a"
intercambiar("ab") -> "ba"

You have attempted of activities on this page