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, remainder that takes two numbers, x and y and returns the remainder of
dividing x by y.
Example:
>>> remainder(5, 3)
2
Write a function, quotient that takes two numbers, x and y and returns the quotient of
dividing x by y.
Example:
>>> remainder(5, 3)
1
Write a function, equal that takes two numbers and returns True if they are equal, or False otherwise.
Write a function, is_balanced_split that takes two numbers, x and y and returns True
if the remainder and the quotient of dividing x by y are equal. It returns False otherwise.
Example:
>>> is_balanced_split(8, 3)
True
>>> is_balanced_split(6, 5)
True
>>> is_balanced_split(5, 3)
False
Restrictions:
- You cannot use %, // or == inside this function's body
- Body of the function should have only one line
Write a function, final_score(a: int, b: int, c: int), that takes three test scores and returns final score, which is the sum of average three test score and the bonus. The bonus should be calculated as follows:
- if average score is above 80, student gets 5 bonus points
- if average score is between 50 and 80 (including both), student gets 2 bonus points
- if average score is below 50 student doesn't get any bonus point
Write a function that takes one number, and returns True if it ends with 4, or False otherwise.
Example:
>>> ends_with(14)
True
>>> ends_with(13)
False
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, 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
def quotient(a, b):
return a // b
def sub(a, b):
return a - b
def calculate(x, y):
if quotient(x, y) == sub(x, y):
return quotient(x, y) + sub(x, y)
elif quotient(x, y) == 2:
return quotient(x, y) - sub(x, y)
return quotient(x, y) == quotient(x - 1, y)
Given the above script, what are the results of the following calls:
| calculate(3, 2): | ||
| calculate(7, 2): | ||
| calculate(6, 3): |
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 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 >>>
Complete execution flow of the following program
def quotient(x): return x // 2 def remainder(x): return x % 2 def add(x): return quotient(x) + remainder(x)
>>> add(7) 4 >>> add(10) 5 >>>