Write a function is_even, that takes a number and returns True if it is even, or False otherwise.
Write a function even_or_odd_message, that takes a number and returns "Even" if it is even,
or "Odd" if it is odd.
Restriction: You CANNOT modulus (%) inside this function's body.
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?
Complete execution flow of the following program
def divide(n): while True: break n = n / 2 print('done') print('DONE') return n res = divide(8)
Write a function is_positive, that takes a number and returns True if it is positive, or False otherwise.
Write a function describe_number, that takes a number and returns "Positive" if it is positive,
or "Non-positive" otherwise.
Restriction: You CANNOT use any relational operator inside this function's body
(<, >, !=, ...).
Write a function, battery_status(charge: int) that returns the current battery condition:
- It returns "full" if charge is 80 or higher
- It returns "normal" if charge is between 30 and 79 (including both)
- It returns "low" if charge is below 30
In Babrruja, there's a rule for who gets invited to the annual birthday party.
The guest must either be a teenager, between 13 and 19 years old (inclusive),
and enjoy video games, or be someone who loves outdoor activities but is 25 years old or younger.
Write a function that checks if a person gets an invite by taking their age and interest.
Print True if they qualify for an invitation, and False otherwise. Examples:
>>> check_invite(14, "video games") True >>> check_invite(21, "outdoor activities") True >>> check_invite(5, "outdoor activities") True >>> check_invite(15, "hiking") False >>> check_invite(21, "video games") False
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 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
def power(x, y): return x ** y def sub(x, y): return power(x - y, x) res = sub(3, 1) print(res)
8 >>>
Complete execution flow of the following program
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
>>> calculate(False, 80) 80 >>> calculate(True, 200) 160.0 >>>