Exercises: Control Flow
How to run these
Download
starter.py below, then run
python3 starter.py.
1 Greatest of two
Given a = 45 and b = 78, print whichever is greater using if-else.
2 Even or odd
Given number = 17, print whether it's even or odd using if-else and %.
3 Leap year check
Given year = 2024, print whether it's a leap year (divisible by 4 AND (not divisible by 100 OR divisible by 400)).
🐞 Task 4 — Debug the Code
This elif chain is supposed to grade 90 as "A" but always prints "D". Find and fix the ordering bug.
score = 90
if score >= 40:
grade = "D"
elif score >= 50:
grade = "C"
elif score >= 60:
grade = "B"
elif score >= 75:
grade = "A"
else:
grade = "Fail"
print("Grade:", grade)