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, 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.
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 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, 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, 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, quotient that takes two numbers, x and y and returns the quotient of
dividing x by y.
Example:
>>> remainder(5, 3)
1
Write a function, equal that takes two numbers and returns True if they are equal, or False otherwise.
Write a function, is_balanced_split that takes two numbers, x and y and returns True
if the remainder and the quotient of dividing x by y are equal. It returns False otherwise.
Example:
>>> is_balanced_split(8, 3)
True
>>> is_balanced_split(6, 5)
True
>>> is_balanced_split(5, 3)
False
Restrictions:
- You cannot use %, // or == inside this function's body
- Body of the function should have only one line
def quotient(x):
return x // 2
def remainder(x):
return x % 2
def add(x):
return quotient(x) + remainder(x)
Given the script above, what is the return value of the following expressions:
| add(2): | ||
| add(5): | ||
| add(13): |
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 add(a, b): while a < b: a = a + 1 return a def multiply(n): while n < 5: n = n * 2 return n res = add(5, 7) + multiply(4)
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 >>>