Conditional Statements · Python example
Map a numeric score to a letter grade using an if-elif ladder.
An if-elif ladder checks conditions in order and stops at the first match. This is a natural fit for grade boundaries.
score = 87
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
elif score >= 60:
grade = "D"
else:
grade = "F"
print(f"Score: {score}")
print(f"Grade: {grade}")