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 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 >>>
Write a function, add that takes two numbers and returns their sum.
Write a function that takes three numbers and returns their sum.
Restriction: You cannot use + inside this function's body
Hint: You can use add, the function you defined above
ⓘ
Define a function, is_even, which takes one number, n, and returns True if it is even, False otherwise.
Define a function, add_evens, which takes one positive integer, n,
and returns sum of all even numbers between 0 and n (inclusive). Example:
>>> add_evens(4)
6
>>> add_evens(7)
12
>>>
Restrictions:
- You cannot use %
ⓘ
Write a function, pow, which takes two numbers as arguments, x and y and returns x to the power of y
Write a function, multiply, which takes two numbers as arguments, a and b and returns their product.
Write a function, that takes two numbers, num1 and num2,
and returns (num1 ** num2) * num2.
Restrictions:
- You cannot use ** or * inside this function's body
- You should use pow to calculate num1 ** num2 and multiply to calculate result of
power * num2.
ⓘ
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
ⓘ
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 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 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 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)