Best afterChoosing one branch with if / else
The elif ladder: order matters
An if/elif ladder stops at the first branch that's true and skips the rest. So the order of the tests is the logic — put the loosest band first and the strict ones become unreachable. Watch a 95 get the wrong grade.
Grade a score of 95: 90+ is an A, 80+ a B, 70+ a C, anything lower a D.
Loosest test first execution-derived · CPython
4elif score >= 70:5 grade = "C"6elif score >= 80:7 grade = "B"8elif score >= 90:9 grade = "A"variables
state after line 1 runs
| variable | value |
|---|---|
score | 95 |
step 1 / 3
Click a line, drag the slider, or use the ← → keys.
What you are looking at
Watch grade, and which test the ladder stops at.
- Buggy — The ladder tests
>= 60first. 95 passes it immediately, sograde = 'D'and the>= 90branch is never reached. - Procedural — Reordered strictest-first,
>= 90is tested first, so a 95 correctly becomes'A'. A ladder must go narrowest-band-first.
Every state you see came from running the program under CPython's tracer at build time — see how GlassBox stays honest.