CurriculumPython if, elif and else for KidsOrder and overlap
Why elif Order Changes the Answer in Python
Why elif's ORDER can make a branch impossible to reach — and when separate ifs are the right call instead.
Order and overlap
You know elif stops at the first match. Here's a trap that causes: writing the conditions in the wrong ORDER.
score = 95. This chain checks the LOOSE condition first — watch what happens to the branch below it.
score = 95
if score > 50:
print("Good")
elif score > 80:
print("Excellent")Output
GoodExcellent never prints — and it NEVER CAN, for any score. Every value bigger than 80 is also bigger than 50, so the first check always wins first.
Fix it by putting the NARROWEST, most specific condition first. Same two conditions, opposite order.
score = 95
if score > 80:
print("Excellent")
elif score > 50:
print("Good")Output
ExcellentSame rule, now with score = 60 — it doesn't satisfy > 80, so it falls through to check > 50 instead.
elif only checks each condition if every one above it was False — so the order you write them in changes what's actually reachable.
score = 60
if score > 80:
print("Excellent")
elif score > 50:
print("Good")Output
GoodNow a completely different question: does everything with more than one condition NEED elif? No.
burns_survived = 3, rooms_found = 5 — two UNRELATED facts. Both badges should be earned. elif here would be the bug.
burns_survived = 3
rooms_found = 5
if burns_survived >= 3:
print("Fireproof")
elif rooms_found >= 5:
print("Explorer")Output
FireproofExplorer never printed — elif skipped it because Fireproof's condition already matched. But these facts don't compete, so that's wrong.
Two SEPARATE ifs fix it — each one checked on its own, so both badges can be earned in the same run.
burns_survived = 3
rooms_found = 5
if burns_survived >= 3:
print("Fireproof")
if rooms_found >= 5:
print("Explorer")Output
Fireproof
ExplorerThe rule: elif for tiers of ONE thing, where only one should ever win. Separate ifs for independent facts, where more than one can be true.
Check your understanding
score = 95. What does this print? if score > 50: print("Good") elif score > 80: print("Excellent")
score = 95
if score > 50:
print("Good")
elif score > 80:
print("Excellent")Why: Good — and Excellent can NEVER print with this ordering, for ANY score. Every number that satisfies score > 80 also satisfies score > 50, and score > 50 is checked first. Writing the narrower, more specific condition FIRST is what makes a branch reachable at all.
burns_survived = 3, rooms_found = 5 — the adventurer earned BOTH badges. Which code correctly awards both?
if burns_survived >= 3:
print("Fireproof")
??? rooms_found >= 5:
print("Explorer")Why: Two separate ifs — because Fireproof and Explorer are independent facts, not competing tiers. elif would silently drop Explorer the moment Fireproof matched, the same order-sensitivity trap as an unreachable elif branch, just from the opposite direction: chaining things that were never supposed to compete.
What you'll practice
points = 95. Give exactly one reward tier: 90 or more is Platinum, 70 or more (but under 90) is Gold, anything else is Silver. Write the chain with the NARROWEST, highest condition FIRST — if you check the loose condition first, the tight one can never be reached.
More from this topic
Order and overlap is one lesson inside Python if, elif and else for Kids — see the full lesson order and what the whole topic covers.
View the full topic →