Lesson 6 of 21 · 2 min
if-elif-else — Multiple Choices
The WHY — Why elif?
Sometimes there are more than two options. A grade calculator has A, B, C, D, and Fail — five options. elif (short for "else if") lets you chain multiple conditions. Python checks them in order and runs the FIRST one that is True, then skips all the rest.
score = 78 # student's exam score
if score >= 90: # check first: is it 90 or above?
grade = "A" # only reaches here if score is 90+
elif score >= 80: # only checked if first condition was False
grade = "B" # only reaches here if score is 80-89
elif score >= 70: # only checked if first two conditions were False
grade = "C" # only reaches here if score is 70-79
elif score >= 60: # only checked if first three conditions were False
grade = "D" # only reaches here if score is 60-69
else: # runs if NONE of the above conditions were True
grade = "F" # only reaches here if score is below 60
print(f"Your grade is: {grade}") # display the final grade
Output: Your grade is: C
Key rule: Only ONE block ever runs — the first condition that is True. Python does not check the rest after finding a match.
Another Example: BMI Category
bmi = 22.5 # Body Mass Index value
if bmi < 18.5: # is the person underweight?
category = "Underweight"
elif bmi < 25: # is the person in normal range?
category = "Normal"
elif bmi < 30: # is the person overweight?
category = "Overweight"
else: # above 30
category = "Obese"
print(f"BMI {bmi} is classified as: {category}") # display result
Output: BMI 22.5 is classified as: Normal
