Python If-Elif-Else (Multi-Path Decisions)
What if you have more than two outcomes? Grade scores can be A, B, C, D, or F. Traffic lights can be Green, Yellow, or Red. The elif (short for "else if") keyword allows you to chain as many sequential checks as you need.
"Think of a multiple-choice quiz. Python checks Option A (if). If False, it checks Option B (elif). If False, it checks Option C (elif). As soon as one matches, it takes that answer and skips the rest of the test."
Deep Dive: How It Works
Execution Order: Python checks conditions from top to bottom. The VERY FIRST condition that evaluates to True executes its block, and Python immediately skips the rest of the entire ladder!
You can have as many elif blocks as you want between the initial if and the optional closing else.
Order Matters: Place your most specific conditions at the top. If you check score > 50 before score > 90, a score of 95 will trigger the > 50 branch first and miss the > 90 branch.
Syntax Blueprint
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
else:
grade = "F"Python tests each branch in sequence and exits the ladder at the first match.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using separate if statements instead of elifWhy it happens: Writing multiple ifs causes EVERY check to run independently, potentially triggering multiple outputs.
How to fix: Use elif to link checks together into a single mutually exclusive chain.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Categorize age groups with if-elif-else
Given age = 15, write an if-elif-else ladder:
If age < 13, print "Child".
Elif age < 20, print "Teenager".
Else, print "Adult".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.