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.
Define a function, category, that takes one number, age,
and:
- It returns "child" if age is lower than 13
- It returns "teen" if age is between 13 and 18 (including 13)
- It returns "adult" if age is between 18 and 65 (including 18)
- It returns "senior" otherwise.
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 a driver's speed speed and a boolean is_birthday.
Return:
- 0 for no ticket if speed <= 60 (or 65 on birthday)
- 1 for small ticket if speed <= 80 (or 85 on birthday)
- 2 for big ticket otherwise
Example:
>>> ticket(64, True)
0
>>> ticket(64, False)
1
At Pupci Academy, employees get a bonus if they meet certain conditions.
If an employee has been at the company for more than 3 years and completed more than 5 projects,
or if they've completed at least 2 projects and their performance rating is higher than 4.0, they receive a bonus.
Write a function that has checks eligibility based on years at company (years), projects completed (projects),
and performance rating (rating). Print True if they qualify for the bonus, and False otherwise. Examples:
>>> check_bonus(years=4, projects=6, rating=1.0) True >>> check_bonus(years=1, projects=2, rating=4.1) True >>> check_bonus(years=3, projects=5, rating=4.0) False
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
def calculate(attendance, grade): total = grade * 0.8 + attendance * 0.2 passes(total) def passes(total): print(total > 6.0)
Given the above script, what is the result of the following expressions?
calculate(10, 10): | ||
calculate(10, 5): | ||
passes(6.01): |
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 print_pow(x, y): print(x ** y) result = print_pow(2, 4) print(result)
Complete execution flow of the following program
def sum(n): total = 0 for i in range(n): total = total + i return total print(sum(3))