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
(<, >, !=, ...).
Write a function power, that takes two integers, a and b, and returns a to the power of b.
Write a function product, that takes two integers, a and b, and returns their product.
Write a function divisible, that takes two integers, x and y, and returns True if x is fully divisible by y, and False otherwise.
Write a function calculate, that takes two integer, n and m and:
- It returns n to the power of m if n is even and m is odd.
- It returns m to the power of n if n is odd and m is even.
- It returns their product otherwise.
Restriction: You CANNOT use modulus (%) or any relational operator (<, >, !=, ...)
inside this function's body.
Write a function, pow, which takes two numbers as arguments, x and y and returns x to the power of y
Write a function, multiply, which takes two numbers as arguments, a and b and returns their product.
Write a function, that takes two numbers, num1 and num2,
and returns (num1 ** num2) * num2.
Restrictions:
- You cannot use ** or * inside this function's body
- You should use pow to calculate num1 ** num2 and multiply to calculate result of
power * num2.
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 %
A taxi charges:
- $4 for the first km
- $2 for each km from 2 to 10
- $1.50 for each km beyond 10
Write a function that takes the number of kilometers traveled and returns the total fare. Example:
>>> taxi_meter(1)
4
>>> taxi_meter(2)
6
>>> taxi_meter(10)
22
>>> taxi_meter(15)
29.5
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
(<, >, !=, ...).
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): |
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): |
Complete execution flow of the following program
def calculate(): add() sub() def add(): a = 2 a = a + a a def sub(): add() calculate()
>>>
Complete execution flow of the following program
def quotient(x, y): return x // y def remainder(x, y): return x % y def add(x, y): return quotient(x, remainder(x, y))
>>> add(4, 3) 4 >>> add(8, 3) 4 >>>