Best afterNumbers have types: int vs float
Operator precedence: × before +
Python doesn't read arithmetic left to right — it follows the usual maths rules, doing multiplication before addition. If you meant the addition to happen first, you have to say so. Watch the same numbers give two different totals.
Add base (2) and extra (3), then multiply the sum by 4 (we want 20).
Forgetting the parentheses execution-derived · CPython
variables
state after line 1 runs
| variable | value |
|---|---|
base | 2 |
step 1 / 3
Click a line, drag the slider, or use the ← → keys.
What you are looking at
Watch result: the order the operators run in decides the answer.
- Buggy —
result = base + extra * 4computes3 * 4 = 12first, then+ 2, giving14— not the20we wanted. - Procedural —
result = (base + extra) * 4forces the addition first:5 * 4 = 20. Parentheses make the order explicit.
Every state you see came from running the program under CPython's tracer at build time — see how GlassBox stays honest.