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
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 (<, >=, ...).
Define a function, are_equal, which takes two values, and returns True if they are equal, False otherwise.
Define a function, get_count, which takes one word and one character, s and char,
and returns how many times char appears in s,
till it becomes char. Example:
>>> get_count('abaa', 'a')
3
>>> get_count('abaa', 'b')
1
>>>
Restrictions:
- You cannot use == or !=
- You cannot use method count of strings
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
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 %
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)
Given the above script, what are the results of the following calls:
| aaa('po', 0): | ||
| aaa('jo', 0): | ||
| aaa('po', 2): |
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): |
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 divide(a, b): while a > b: a = a / 2 return a def sub(b): i = 0 while i < 10: i = i + b return i res = sub(10) + divide(6, 2)