Write a function double_letters, which takes a string, s, and returns a string with every
character duplicated.
Example:
>>> double_letters("go")
"ggoo"
>>> double_letters("ani")
"aannii"
Write a function that takes two integers, n and m, (where n > m) and prints all numbers between n and m (including n but not m). You should use while statement.
Create a function, random_char, that takes a string, s, as argument, and returns a random letter from the given string.
Define a function, can_vote, that takes one integer and one string, age and citizenship,
and returns:
- "eligible" if age is 18 or older and citizenship is "yes"
- "too young" if age is less than 18
- "not a citizen" if citizenship is not "yes"
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 that takes one positive integer as argument, n and prints numbers from 0 to n (including both), each in a new line.
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 clothing_recommendation(temperature, is_raining):
if temperature < -50 or temperature > 60:
return "Invalid"
elif temperature >= 25:
if is_raining == "yes":
return "Light clothes and umbrella"
else:
return "Light clothes"
elif 15 <= temperature <= 24:
return "Jacket"
else:
return "Coat"
Given the above script, what are the results of the following calls:
| clothing_recommendation(25, "no"): | ||
| clothing_recommendation(25, "yes"): | ||
| clothing_recommendation(24, "yes"): |
Complete execution flow of the following program
def add(a, b): print(a + b ** b) def sub(x, y): print(x - y) add(x + x, x + y) sub(1, 2)
-1 29 >>>
Complete execution flow of the following program
def forward(a, b): a = a * a a = a + a + b print(a) def backward(a, b): a = a / a forward(a, b) a = a + b backward(3, 4)
6.0 >>>