If / Elif / Else
if lets your program choose a path.
Like a fork in a road.
If the check is True, take this path.
If not, try another path, or skip ahead.
A simple if
Write if, then a True/False check, then a colon.
Indent the lines that belong to that choice.
if and else
else is the other road.
It runs when the if check is False.
elif for more choices
elif means else if.
Python checks from the top.
It runs the first True block, then skips the rest.
if: first check
elif: next checks
else: when nothing above matched
Only one block in the chain runs
Nested if
You can put an if inside another if.
Like opening a big gate, then a small gate.
Keep nesting shallow when you can. Clear beats deep.
Many checks on one line
You can use and and or inside the if check.
A tiny decision game
Put the ideas together.
Tip: Indent with 4 spaces under each colon. Matching spaces keep Python happy.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.