Define a function max_of_two, that takes two numbers, a and b,
and returns the larger of the two numbers.
Restriction: You cannot use max or min functions.
Define a function, max_of_four, that takes four numbers, w, x, y and z,
and returns the largest of the four numbers.
Restriction: You cannot use max, min or any relational operator (<, >=, ...).
Complete execution flow of the following program
def divisible(n, m): if n % m == 0: return 1 return 2 def get_sum(x): total = 0 for i in range(x): if total == 1: print(total) total = 0 total = total + divisible(i, 3) return total res = get_sum(2)
1 >>>
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, 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, divisible that takes two numbers, x and y and returns True
if x is divisible by y. It returns False otherwise.
Example:
>>> divisible(4, 2)
True
>>> divisible(3, 2)
False
Restriction: You cannot use % or // inside this function's body
Write a function, even_remainder that takes two numbers, x and y and returns True
if remainder of dividing x by y is even. It returns False otherwise.
Example:
>>> even_remainder(4, 2)
True
>>> even_remainder(3, 2)
False
>>> even_remainder(30, 12)
True
Restrictions:
- You cannot use %, // or == inside this function's body
- Body of the function should have only one line
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
Define a function, are_equal, which takes two values, and returns True if they are equal, False otherwise.
Define a function, print_chars, which takes one word and one character, s and char,
and prints all characters of s, each in a new line,
till it becomes char. Example:
>>> print_chars('ani', 'i')
a
n
>>> print_chars('psejo', 'j')
p
s
e
>>>
Restrictions: You cannot use == or !=
def add(a, b):
while a < b:
a = a + 1
return a
def multiply(n):
while n < 5:
n = n * 2
return n
Given the above script, what are the results of the following expressions:
| add(2, 4): | ||
| multiply(3): | ||
| add(1, 2) + multiply(1): |
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 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 >>>
Complete execution flow of the following program
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(4, 4)