My Day✳All blog articles ↗

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.

x: 2 → 3; final y: 2
x: 2 → 3; final y: 2

What to do

  1. Copy the lines in execution order and prepare separate state entries for each name.
  2. For each line, evaluate the right side using the preceding state, then update only its target name.
  3. 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.

Buy My Day for Windows ↗