Define a function, add, which takes two numbers, a and b, and returns their sum.
Define a function, add_up_to, which takes one positive integer, n,
and returns sum of all numbers between 0 and n (inclusive). Example:
>>> add_up_to(4)
10
>>>
Restrictions:
- You cannot use range
- You cannot use +
- You cannot use sum
Define a function, divisible, which takes two number, n and m,
and returns True if n is divisible by m, False otherwise. Example:
>>> divisible(4, 2)
True
>>> divisible(5, 2)
False
Define a function, divisibles_prod, which takes one positive integer, x,
and returns production of all odd numbers between 1 and x (not including x).
Example:
>>> divisibles_prod(5)
3
>>> divisibles_prod(6)
15
Restrictions:
- You cannot use %
Write a function late, that takes an integer, minutes, and returns True if it is greater than or equal to 5, and False otherwise.
Write a function evaluate_lateness, that takes an integer, minutes and:
- It returns "good" if minutes is less than 5
- It returns "late" if minutes is between 5 and 9 (including both)
- It returns "too late" if minutes is between 10 and 14 (including both)
- It returns "unacceptable" if minutes is greater than or equal to 15
Restriction: You CANNOT use any relational operator inside this function's body
(<, >, !=, ...).
Write a function, multiply that takes two numbers and returns their product.
Write a function that takes three numbers and returns their product.
Restriction: You cannot use * inside this function's body
Hint: You can use multiply, the function you defined above
Write the above formula (pythagorean theorem) in python, representing it as a function.
Write a function pythagorean_theorem, which takes two numbers, a and b, and returns c.
Write a function, hypotenuse_times_3, that takes a and b as arguments,
it finds c using pythagorean_theorem, and returns the result of c * 3
Write a function is_low_battery, that takes an integer, level, and returns True if it is below 20, and False otherwise.
Write a function battery_status, that takes an integer, level and:
- It returns "critical" if level is below 5
- It returns "low" if level is between 5 and 19 (including both)
- It returns "normal" if level is 20 or above
Restriction: You CANNOT use any relational operator inside this function's body
(<, >, !=, ...).
def a(x):
return x % 3 == 0
def b(w, y):
if w == y:
return True
return False
def ani(x, y):
if not b(x, y):
return a(x)
elif b(x, y) and not a(x):
return 'jo more'
return b(x, y)
ani(3, 3)
ani(5, 5)
Given the above script, what are the results of the following calls:
| ani(3, 3): | ||
| ani(5, 5): |
def quotient(x):
return x // 2
def remainder(x):
return x % 2
def add(x):
return quotient(x) + remainder(x)
Given the script above, what is the return value of the following expressions:
| add(2): | ||
| add(5): | ||
| add(13): |
Complete execution flow of the following program
def double(a): return a + a def sub(x, y): return x - y def calculate(m, n): return double(sub(m, n) + sub(m, n)) print(calculate(2, 1))
4 >>>
Complete execution flow of the following program
def is_po(s): if s == 'po': return True return False def is_zero(n): return n == 0 def aaa(a, b): if not is_po(a) and is_zero(b): return is_po(a) elif not is_zero(b): return 'pse' else: return is_po(a) and is_zero(b) aaa('pse', 0)