Write a function that takes two numbers, x and y, where y is a single digit number,
and returns True if x ends y, or False otherwise.
Example:
>>> ends_with(16, 6)
True
>>> ends_with(34, 3)
False
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, 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
A taxi charges:
- $4 for the first km
- $2 for each km from 2 to 10
- $1.50 for each km beyond 10
Write a function that takes the number of kilometers traveled and returns the total fare. Example:
>>> taxi_meter(1)
4
>>> taxi_meter(2)
6
>>> taxi_meter(10)
22
>>> taxi_meter(15)
29.5
Complete execution flow of the following program
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 == 1: print(total) total = 0 total = total + divisible(i, 3) return total res = get_sum(2)
1 >>>
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):
return x // 2
def remainder(x):
return x % 2
def add(x):
return quotient(x) + remainder(x)
| 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)
| calculate(3, 3): | ||
| calculate(3, 4): | ||
| calculate(3, 2): |
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)
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)