if, elif, and else
Scenario: A monitor must label response times healthy, slow, or critical.
New words, in plain English
- Control flow - the order in which instructions run
- Condition - an expression treated as True or False
- Branch - one possible path through a decision
An if tests first, elif adds ordered alternatives, and else catches everything remaining. Indentation defines each branch.
Analogy: A Python program is like a clear set of instructions for a careful helper: names label things, indentation groups steps, and errors explain where the helper became confused.
A small, real example
ms = 850
if ms >= 1000:
label = "critical"
elif ms >= 500:
label = "slow"
else:
label = "healthy"
Tip: Put narrower or higher thresholds before broader ones.
Goal: Practice this idea in the py-conditionals-loops challenge at/labs/python. Fix the broken program, run it yourself, then usecheckto prove the real end state.