Best afterNumbers have types: int vs float
Converting a float to an int
Turning a decimal into a whole number sounds like rounding — but Python's int() doesn't round. Watch 3.9 become two different whole numbers depending on which function you reach for.
Round the measurement 3.9 to a whole number (we want 4).
int() truncates, it doesn't round execution-derived · CPython
variables
state after line 1 runs
| variable | value |
|---|---|
measurement | 3.9 |
step 1 / 2
Click a line, drag the slider, or use the ← → keys.
What you are looking at
Watch rounded — does 3.9 become 3 or 4?
- Buggy —
rounded = int(3.9)gives3.int()truncates — it chops the fractional part off rather than rounding to the nearest. - Procedural —
rounded = round(3.9)gives4. When you actually want rounding,round()is the tool.
Every state you see came from running the program under CPython's tracer at build time — see how GlassBox stays honest.