Write a function, add that takes two numbers and returns their sum.
Write a function, average that takes three numbers and returns their average.
Restriction: You cannot use + inside this function's body
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
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
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 >>>
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
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
def quotient(a, b): return a // b def sub(a, b): return a - b def calculate(x, y): if quotient(x, y) == sub(x, y): return quotient(x, y) + sub(x, y) elif quotient(x, y) == 2: return quotient(x, y) - sub(x, y) return quotient(x, y) == quotient(x - 1, y)
Given the above script, what are the results of the following calls:
calculate(3, 2): | ||
calculate(7, 2): | ||
calculate(6, 3): |
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): |
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)
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)