CurriculumPython if, elif and else for Kidselif and else
Python elif and else: Chains of Decisions Explained
Chains of decisions — and why the ORDER and the KIND of check both matter.
elif and else
You know if. Now let's chain several questions together, and add a catch-all for everything else.
elif means 'otherwise, if THIS is true' — it only gets checked if everything above it was False.
gold = 150
if gold >= 100:
print("So generous!")
elif gold > 0:
print("Thank you.")Output
So generous!else is the catch-all at the end — no condition of its own, it just catches whatever nothing else matched.
gold = 0
if gold >= 100:
print("So generous!")
elif gold > 0:
print("Thank you.")
else:
print("...")Output
...Here's the important part. An elif chain STOPS at the first True — even if a later condition would ALSO be true.
strength = 90
if strength > 80:
print("Legendary!")
elif strength > 50:
print("Strong.")Output
Legendary!90 is more than 50 too — but you never see 'Strong', because elif already stopped at Legendary. Only one branch ever runs.
Compare that to two SEPARATE ifs — those don't stop each other. Both can fire on the same number.
strength = 90
if strength > 80:
print("Legendary!")
if strength > 50:
print("Strong.")Output
Legendary!
Strong.Check your understanding
strength = 90. Which of these will print BOTH Legendary and Strong?
Why: Two separate ifs check independently, so both can fire on the same value: Legendary AND Strong. if/elif is a CHAIN — it stops at the first match, so only Legendary prints. They agree on most values, but not on this one, which is exactly why the difference matters.
gold = 0. What does the else branch need for its OWN condition to run?
if gold >= 100:
print("So generous!")
elif gold > 0:
print("Thank you.")
else:
print("...")Why: else takes no condition of its own — writing else gold == 0: is actually a Python error. It runs automatically whenever nothing above it matched.
What you'll practice
Bring the dragon gold. 100 or more: it calls you generous. Less than 100 but more than 0: it says thanks. Nothing at all: it looks disappointed. You brought 150 gold.
More from this topic
elif and else 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 →