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
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, mean that takes two numbers and returns their mean.
Example:
>>> mean(3, 5)
4.0
Write a function, square that takes a number and returns its square.
Example:
>>> square(3)
9
Write a function, square_of_mean, that takes two numbers and returns square of their mean.
Example:
>>> square_of_mean(4, 6)
25.0
Restriction: You cannot use *. + or / inside this function's body
Complete execution flow of the following program
def is_vowel(char): for vowel in 'aeiou': if char == vowel: return 1 return 0 def count_vowels(s): count = 0 for char in s: count = count + is_vowel(char) if char == 'y': print('reset') count = 0 return count res = count_vowels('bye')
reset >>>
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 !=
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.
def quotient(x, y):
return x // y
def remainder(x, y):
return x % y
def add(x, y):
return quotient(x, remainder(x, y))
Given the script above, what is the return value of the following expressions:
| add(5, 3): | ||
| add(3, 2): | ||
| add(10, 3): |
def power(a, b):
return a ** b
def multiply(a):
return a * a
def calculate(a, b):
if power(a, b) == multiply(a):
return power(a, b) + multiply(a)
elif multiply(a) == multiply(b):
return multiply(a - b)
return multiply(a) == power(a, b)
Given the above script, what are the results of the following calls:
| calculate(3, 3): | ||
| calculate(3, 4): | ||
| calculate(3, 2): |
Complete execution flow of the following program
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) aaa('pse', 0)
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 >>>