if, elif, else
A block in Python is defined by indentation, not braces. The colon opens the block; every line indented under it belongs to it; the first line back at the old indentation ends it. Four spaces is the standard. This is the one rule that makes Python code look the same everywhere.
You should see
Warm
Cart is empty
oddtemperature = 36. Only one branch runs — the first true one. Then rewrite the chain with the ranges in a different order and see what breaks.temperature = 31if temperature > 35:print("Heat warning")elif temperature > 25:print("Warm")else:print("Cold")
Bind temperature to 31.
temperature | 31 |
All 5 steps as a table
| Step | Line | What happened | Variables now |
|---|---|---|---|
| 1 | 1 | Bind temperature to 31. | temperature = 31 |
| 2 | 2 | Evaluate 31 > 35 → False. Skip this block entirely. | |
| 3 | 4 | Evaluate 31 > 25 → True. Enter this block. | |
| 4 | 5 | Print "Warm". Because a branch matched, every remaining elif/else is skipped without being evaluated. | |
| 5 | 7 | Never reached. Only one branch of a chain ever runs. |
IndentationError: expected an indented block after 'if' statement
x = 5
if x > 3:
print("big") File "your code", line 3
print("big")
^
IndentationError: expected an indented block after 'if' statement on line 2The colon promised a block and the next line was not indented, so the parser has no idea what belongs to the if. The cousin error, unindent does not match any outer indentation level, means you mixed indent widths — usually tabs and spaces from two editors.
Indent the body four spaces. Set your editor to insert spaces for Tab.
x = 5
if x > 3:
print("big")