Best afterThe elif ladder: order matters·Modular arithmetic: wrapping around
FizzBuzz
FizzBuzz is the classic warm-up: count to 15, but say Fizz for multiples of 3, Buzz for multiples of 5, and FizzBuzz for both. It looks trivial — until the order of your tests quietly hides a whole case.
For 1 to 15, say Fizz for multiples of 3, Buzz for multiples of 5, FizzBuzz for both, else the number.
FizzBuzz — the branch you can never reach execution-derived · CPython
8 result.append("FizzBuzz")9 else:variables
state after line 1 runs
| variable | value |
|---|---|
result | [] |
step 1 / 65
Click a line, drag the slider, or use the ← → keys.
What you are looking at
Watch the result list fill as i climbs from 1 to 15.
- Buggy — tests
i % 3 == 0first, so 15 (a multiple of both) is caught as 'Fizz' and theelif ... and ...branch for FizzBuzz can never run. - Procedural — tests the both-divisible case first, so 15 correctly becomes 'FizzBuzz'. Same conditions, different order.
This is a milestone — it puts several earlier ideas together into one small program.
Every state you see came from running the program under CPython's tracer at build time — see how GlassBox stays honest.