← All lessons

elif: several options

Sign in · Sign up

Lesson 2.4

When there are more than two options, elif goes between if and else:

if score >= 90:
    print("Excellent")
elif score >= 70:
    print("Good")
else:
    print("Practice more")

The chain is checked from top to bottom: the first true condition runs and the rest are skipped. That's why stricter conditions go higher.

Grade the score score:

Score Word
90 and above Excellent
70 to 89 Good
50 to 69 Okay
below 50 Practice more

score is set by the check, so do not write the line score = ....

Hint

The top-to-bottom order matters: check from the highest score down to the lowest.

The first branch is >= 90, then >= 70, >= 50, and the last one is else. If you change the order, the first matching branch runs.