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.
At Traukni School, students can join the school's sports team if they meet the criteria.
To join, a student must have a GPA greater than 3.5 and be part of the track team,
or they must be in the top 10% of their class academically.
Write a function that takes student's gpa: float, track_team: bool and top_10_percent: bool and prints True
if they qualify, and False otherwise.. Examples:
>>> check_sports_team(gpa=3.6, track_team=True, top_10_percent=False) True >>> check_sports_team(gpa=3.5, track_team=True, top_10_percent=True) True >>> check_sports_team(gpa=3.5, track_team=False, top_10_percent=False) False >>> check_sports_team(gpa=2.6, track_team=True, top_10_percent=False) False
Define a function, check_number, that takes one number, n, and returns "positive" if n is greater than 0, "negative" if n is less than 0, and "zero" otherwise.
Define a function, fruit_color, that takes one string, fruit,
and:
- It returns "red" if fruit is "apple".
- It returns "yellow" if fruit is "banana".
- It returns "orange" if fruit is "orange".
- It returns "unknown" otherwise.
Write a function that takes hours parked, integer, and is_member, boolean,
and returns the fee to pay:
- First hour is free
- Members pay $1/hour
- Non-members pay $2/hour
- Max fee is $10
Example:
>>> calculate_fee(1, True)
0
>>> calculate_fee(3, True)
2
>>> calculate_fee(3, False)
4
Define a function, concatenate, which takes two strings, s1 and s2,
and returns their concatenation. Example:
>>> concatenate('ani', 'pse')
'anipse'
Define a function, print_chars, which takes two strings, s1 and s2,
and using only one for loop it prints all the characters of s1 and s2,
each in a new line, in the order that they appear. Example:
>>> print_chars('ab', 'cd')
a
b
c
d
>>>
Restrictions:
- You should use exactly one for
- You cannot use +
def traffic_light_decision(light_color, street_clear):
if light_color == "green":
if street_clear == "yes":
return "Go!"
else:
return "Wait!"
elif light_color == "yellow":
return "Slow down!"
elif light_color == "red":
return "Stop!"
else:
return "Invalid"
Given the above script, what are the results of the following calls:
| traffic_light_decision("yellow", "yes"): | ||
| traffic_light_decision("green", "pse"): | ||
| traffic_light_decision("blue", "yes"): |
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 print_result(a, b): print(a ** b) print_result(2 + 2, 3 - 2) def calculate(a, b, c): print_result(a + b, c - 3) res = a + b + c calculate(3 + 3, 4 - 2, 4)
4 8 >>>