Write a function that takes two positive integers, n and m, and returns sum of all numbers
between 1 and n that are fully divisible by m. Example:
>>> sum_of_divisibles(6, 3)
9
>>> sum_of_divisibles(10, 4)
12
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
(<, >, !=, ...).
Define a function, is_greater, that takes two numbers, a and b, and returns True if a is greater than b, otherwise False.
Define another function, count_greater_than, that takes three numbers,
n, a, b and c, and returns the count of how many of the three numbers a, b, and c
are greater than n.
Example:
>>> count_greater_than(1, 2, 2, 3)
3
>>> count_greater_than(2, 2, 2, 3)
1
>>> count_greater_than(6, 5, 2, 3)
0
Restriction: You cannot use max, min or any relational operator (<, >=, ...).
Write a function abs, that takes one integer and returns its absolute value.
Write a function add, that takes two integers, a and b, and returns their sum.
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 one integer, n, and:
- It returns 7 if n is fully divisible by 7.
- It returns its absolute value if n is fully divisible by 3 and 4.
- It returns its double if n is not fully divisible by 3 and 4.
- It returns its None otherwise.
Examples:
>>> calculate(14)
7
>>> calculate(-12)
12
>>> calculate(13)
26
>>> calculate(8)
>>>
Restriction: You CANNOT use any arithmetic operator (+, -, ...),
modulus (%), or any relational operator (<, >, !=, ...)
inside this function's body.
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
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 calculate(x, y): res = x * y res = x + res revert(res, x, y) def revert(a, b, c): res = a - b res = res / c print(res) calculate(2, 3)
2.0 >>>
Complete execution flow of the following program
def calculate(): add() sub() def add(): a = 2 a = a + a a def sub(): add() calculate()
>>>