Write a function that takes a number and:
- It returns "even" if it is divisible by 2 and 6
- It returns "odd" if it is divisible by 3 and 5
- It returns "all" if it is divisible by 2, 3, 5 and 6
- It returns "no" otherwise
Example:
>>> check_divisibility(6)
even
>>> check_divisibility(30)
all
>>> check_divisibility(15)
odd
>>> check_divisibility(7)
no
def add(a, b):
print(a + b ** b)
def sub(x, y):
print(x - y)
add(x + x, x + y)
sub(1, 2)
Write the printed values, in order, after the execution of the above script?
Write a function, sum_range, that takes two positive integers, a and b,
and using a while True, it calculates the sum of all numbers from a to b (inclusive),
and returns it. Assume a <= b.
Example:
>>> sum_range(2, 4)
9
Restriction: You cannot use for or if.
Write a function, bonus_points(level: int), that gives extra points based on performance level:
- if level is 3, return 5 bonus points
- if level is 2, return 2 bonus points
- if level is 1, return 0 bonus points
def first():
print(3)
def second():
first()
first()
def third():
second()
second()
first()
second()
third()
After the execution of the above script:
| Which value is printed: | ||
| How many times is the value printed: |
Write a function that takes a value as argument and using a for loop it prints it 3 times, one per line.
def add(n):
total = 10
for num in range(n):
total = total + 2
return total
Given the above script, what are the results of the following expressions:
| add(1): | ||
| add(2): | ||
| add(5): |
def divide(n):
while True:
break
n = n / 2
print('done')
print('DONE')
return n
res = divide(4)
Given the above script:
| What is the value of res: | ||
| What is the printed value: |
Complete execution flow of the following program
x = -9 y = 0 if x > 0: if y > 0: print("first") elif y == 0: print("second") else: print("third") elif x == 0: if y > 0: print("fourth") elif y == 0: print("fifth") else: print("sixth") else: if y > 0: print("seventh") elif y == 0: print("eighth") else: print("ninth") print("Finish")
"eighth" "Finish" >>>
Complete execution flow of the following program
def compare(a): print_arg(a == 0 or a == 1) print_arg(a < 0 or a > 10) def print_arg(x): print(x) compare(4)
False False >>>