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 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
ⓘ
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 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
ⓘ
Define a function, add, which takes two numbers, a and b, and returns their sum.
Define a function, add_up_to, which takes one positive integer, n,
and returns sum of all numbers between 0 and n (inclusive). Example:
>>> add_up_to(4)
10
>>>
Restrictions:
- You cannot use range
- You cannot use +
- You cannot use sum
ⓘ
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 (<, >=, ...).
ⓘ
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): |
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 quotient(x, y): return x // y def remainder(x, y): return x % y def add(x, y): return quotient(x, remainder(x, y))
>>> add(4, 3) 4 >>> add(8, 3) 4 >>>
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 >>>