Fix the Grade Calculator
Beginner · Fix the bug · from Python If-Else: Conditions, Elif, Nested Ifs, and Ternary
From the lesson: Python If-Else: Conditions, Elif, Nested Ifs, and Ternary
Every day you make hundreds of decisions. If it's raining, you grab an umbrella. If the traffic light is red, you stop. If your phone battery is below 20%, you look for a charger. These are all conditional decisions - you check something and act based on the result.
Read the lessonThis grade calculator has a bug. Every score gets the grade "D" even when it should be "A", "B", or "C". Fix the elif chain so it works correctly.
Expected output for score = 85:
Grade: Bscore = 85
if score >= 60:
grade = 'D'
elif score >= 70:
grade = 'C'
elif score >= 80:
grade = 'B'
elif score >= 90:
grade = 'A'
else:
grade = 'F'
print(f'Grade: {grade}')
More if else exercises
- Even or OddBeginner
- Temperature AdvisorBeginner
- Predict the OutputBeginner
- Ternary Ticket PriceBeginner
- Login ValidatorBeginner
All Python exercises · 50 practice problems · Control Flow quiz