Trace the Variables

One row per line

To trace a program, keep a table with a column for each variable. Read one line, work out the right side with the values the table holds RIGHT NOW, and write the new value in that variable's column. The old value is gone.
Linewk
w = 66
k = 464
w = w * k % 724 % 7 is 34
k -= w ** 234 - 9 is -5
w += k // 23 + (-3) is 0-5
It prints 0 -5. Two things to notice. The third line already uses the new w, which is 3. And -5 // 2 is -3, because floor division rounds down.
The program below prints both variables after each line that changes one. Trace it by hand first, then run it and compare each printed line with your table. Then change it and run it again:
• Change the first line to tiles = 10.
• Change rows -= tiles ** 2 to rows = rows - tiles ** 2, and check that the output stays the same.
tiles = 9
rows = 5
print("tiles:", tiles, "rows:", rows)
tiles = tiles * rows % 8
print("tiles:", tiles, "rows:", rows)
rows -= tiles ** 2
print("tiles:", tiles, "rows:", rows)
tiles += rows // 3
print("tiles:", tiles, "rows:", rows)
Output
Press Run to see what this program prints.

Note: This IDE is for experimenting with the code in this lesson. Your changes are not saved, and refreshing the page puts back the original lesson code.