Control flow · Lesson 8 of 25
Conditions: if, elif and else
In Python indentation isn't style; it's part of the code.
7 minutes3 games
A condition ends with : and the code that belongs to it is indented (4 spaces). Python knows what belongs where from the indentation, not from brackets.
Python
temp = 28
if temp > 35:
print("Very hot")
elif temp > 25:
print("Warm")
else:
print("Cool")| Tool | Use |
|---|---|
| Equal / not equal |
| Both conditions true |
| At least one condition true |
| Negate truth value |
Spot the bug
One line will error. Which?
Order the lines
Order it: print even for even numbers, otherwise odd.
- Click the lines in the right order
Exercise
Print A if marks is 85 or more, otherwise B.
Expected output: A
Python
marks = 91
Learn more from
Played 0 of 3 games
Sign in to save your progress and earn XP.