🔀 Making Decisions, lesson 3 of 5
elif: more than two choices
Chain several conditions with elif; the first true one wins.
9 min
1 exercise
2 quizzes
0/3 solved
Getting Python ready… examples can run in a moment.
When there are more than two options, add elif
("else if") branches. Python checks the conditions
from top to bottom and runs only the first
block whose condition is True. The final else
(optional) catches everything else.
Example
What to wear
Try 30, 18, 17 and -5. Only one line prints each time.
Quiz
What does this print?
excellent
pass
pass
excellent
fail
Exercise
Grade calculator
Set grade from score:
- 90 or more →
"A" - 80 or more →
"B" - 70 or more →
"C" - anything lower →
"F"
Example
Mini program: ride the rollercoaster?
One line per input() call
Try heights of 150, 125 and 100.
Quiz
What does this print?
positive
negative
zero
Nothing