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
ⓘ
Complete execution flow of the following program
def calculate(): add() sub() def add(): a = 2 a = a + a a def sub(): add() calculate()
>>>
Define a function, is_greater, that takes two numbers, a and b, and returns True if a is greater than b, otherwise False.
Define another function, count_greater_than, that takes three numbers,
n, a, b and c, and returns the count of how many of the three numbers a, b, and c
are greater than n.
Example:
>>> count_greater_than(1, 2, 2, 3)
3
>>> count_greater_than(2, 2, 2, 3)
1
>>> count_greater_than(6, 5, 2, 3)
0
Restriction: You cannot use max, min or any relational operator (<, >=, ...).
ⓘ
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 the above formula (pythagorean theorem) in python, representing it as a function.
Write a function pythagorean_theorem, which takes two numbers, a and b, and returns c.
Write a function, hypotenuse_times_3, that takes a and b as arguments,
it finds c using pythagorean_theorem, and returns the result of c * 3
ⓘ
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): |
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.
ⓘ
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
ⓘ
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 %
ⓘ