Trace assignments line by line in a coding exercise
Record each state without treating assignment as a mathematical equation.
For a simple Python assignment, the right side is evaluated before the name is bound to the result. Record the state after each line. Rebinding one name does not automatically rebind another; this example concerns integers only.
What to do
- Copy the lines in execution order and prepare separate state entries for each name.
- For each line, evaluate the right side using the preceding state, then update only its target name.
- Compare successive states and mark names not yet defined without inventing a value for them.
Example
Fictional exercise: x=2; y=x; x=x+1. After the first line, x is 2 and y is undefined. After the second, both are 2; after the third, x is 3 and y remains 2. This is a manual trace, not a reported Python run.
My Day · Windows
Save the state table as text in My Day; it does not execute this code.