Write a function, that takes one numbers as argument, and returns True if it is divisible by 5 but not divisible by 10, False otherwise.
def compare(a, b, c):
print(a == b and a < c)
x, y, z = 1, 2, 3
d = x == 1 and y == 2 and y < z
compare(x, y, -1 * z)
Given the above script:
| What is printed: | ||
| What is the final value of d: |
Write a function, sum_range, that takes two positive integers, a and b,
and returns the sum of all numbers from a to b (inclusive). Assume a <= b.
Example:
>>> sum_range(2, 4)
9
Restriction: You cannot use for or if.
Write a function, recharge(charge: int, amount: int) that returns the battery's charge by the
given amount.
If the new charge exceeds 100, set it to 100 (the maximum capacity).
Example:
>>> recharge(40, 15)
55
>>> recharge(70, 40)
100
Define a function, temp_feel, that takes one number, temp,
and:
- It returns "cold" if temp is lower or equal to 10.
- It returns "cool" if temp is between 10 and 20 (including 20).
- It returns "warm" if temp is between 20 and 30 (including 30).
- It returns "hot" if temp is greater than 30.
Write a function named prod that takes three integers as arguments, and returns their product.
Write a function named sum that takes three integers as arguments, and returns their sum.
Call prod and assign its return value to p
Call sum and assign its return value to s
Raise p to the power of s and print the result
def calculate(member, total):
if member and (total > 100):
return total - total * 0.2
elif member:
return total - total * 0.05
elif total > 100:
return total - total * 0.1
return total
Given the above script, what are the results of the following calls:
| calculate(False, 90): | ||
| calculate(True, 100): | ||
| calculate(False, 200): |
def dosmth(num, string):
for s in string:
num = num + 1
return num
def dosmth2(string):
v = 2
for char in string:
v = v * 2
return v
Given the above script, what are the results of the following expressions:
| dosmth(1, '12345'): | ||
| dosmth2('123'): | ||
| dosmth(0, 'ani') + dosmth2('a'): |
Complete execution flow of the following program
def calculate(a, b): if a == 'first' and b < 0: return b + b elif a != 'first' and b > 0: return b * 2 return b
>>> calculate("third", 3) 6 >>> calculate('first', 4) 4 >>>
Complete execution flow of the following program
v = 'a' n = 10 if v == 'b': n = n + n elif n == 10: n = n + 5 if v == 'a': n = n + 5
>>> n 20 >>>