Trace Table Layout
Draw a table with one column per variable and one row per step. Write the starting value on row 0, then one row per line executed.
Example โ Find Max
lst = [4, 7, 2, 9, 5]
best = lst[0]
for x in lst[1:]:
if x > best:
best = x
print(best)
| Step | x | best |
|---|---|---|
| init | โ | 4 |
| 1 | 7 | 7 |
| 2 | 2 | 7 |
| 3 | 9 | 9 |
| 4 | 5 | 9 |
Rules for Clean Tracing
- Write the full starting state before any loops.
- One column per variable โ never merge.
- Only write the cells that change each step.
- Circle the final printed value.
Practise this on PyForm โ free
PyForm runs Python in your browser with an AI tutor trained for HKDSE. No install, no credit card.
Open PyForm โ