Write a function, adjust_cooling(status: str), that determines the appropriate cooling power
based on the current temperature status:
- "too cold" -> 0.2
- "optimal" -> 0.5
- "too warm" -> 1.0
Example:
>>> adjust_cooling("too warm")
1.0
>>> adjust_cooling("optimal")
0.5
>>> adjust_cooling("too cold")
0.2
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 that takes an integer as argument and:
- It returns 'both' if it is divisible by 13 and 15
- It returns 'either' if it is divisible by 13 or 15
- It returns 'neither' otherwise.
An employer has many employees who work different numbers of hours per day and
receive different payments per hour.
Write a function that takes number of hours, hours, and payment per hour, payment,
and prints the total payment.
Write a function which takes two arguments, n and m.
- If both arguments are integers, and n is equal or less than m, it returns a random integer between n and m
- If both arguments are strings, it concatenates them and returns a random character out of the concatenated string
- It prints "not applicable" otherwise.
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 calculate(num):
for item in '12ab':
num = 2 + num
return num
def calculate2(num, string):
for s in string:
num = num ** 2
return num
Given the above script, what are the results of the following expressions:
| calculate(1): | ||
| calculate2(2, 'nn'): | ||
| calculate(2) + calculate2(3, 'o'): |
def add(n, m):
total = 0
while True:
if total == 100:
break
total = total + n + m
return total
res = add(20, 30)
Given the above script:
| What is the value of res: |
Complete execution flow of the following program
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 d = dosmth2('ab') - dosmth(3, 'ab')
Complete execution flow of the following program
def repeat_acting(): act() print("acting") def act(): print("acting") repeat_acting()
"acting" "acting" >>>