Editor

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 lesson

This 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: B
score = 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

All Python exercises · 50 practice problems · Control Flow quiz