Write a function that takes one number, and returns True if it ends with 4, or False otherwise.
Example:
>>> ends_with(14)
True
>>> ends_with(13)
False
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 (<, >=, ...).
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, 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 %
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 >>>
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 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): |
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('traukni')
print(res)
Given the above script:
| What is the value of res: | ||
| What is the printed value: |
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 double(a): return a + a def sub(x, y): return x - y def calculate(m, n): return double(sub(m, n) + sub(m, n)) print(calculate(2, 1))
4 >>>