Write a function power, that takes two integers, a and b, and returns a to the power of b.
Write a function product, that takes two integers, a and b, and returns their product.
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 two integer, n and m and:
- It returns n to the power of m if n is even and m is odd.
- It returns m to the power of n if n is odd and m is even.
- It returns their product otherwise.
Restriction: You CANNOT use modulus (%) or any relational operator (<, >, !=, ...)
inside this function's body.
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, 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 %
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 a function is_low_battery, that takes an integer, level, and returns True if it is below 20, and False otherwise.
Write a function battery_status, that takes an integer, level and:
- It returns "critical" if level is below 5
- It returns "low" if level is between 5 and 19 (including both)
- It returns "normal" if level is 20 or above
Restriction: You CANNOT use any relational operator inside this function's body
(<, >, !=, ...).
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 (<, >=, ...).
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 == 3:
print(total)
total = 0
total = total + divisible(i, 3)
return total
res = get_sum(3)
Given the above script:
| What is the value of res: | ||
| What is the printed value: |
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): |
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 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 >>>