GCSE Computer Science
Python trace tables โ GCSE Computer Science
What is a trace table?
A trace table is a way of tracking the value of variables as code runs, line by line. You record what each variable holds after every step โ so instead of running the code in your head all at once, you slow it down into small, manageable moves. It's the same process a debugger uses, except you do it by hand on paper.
Trace tables are a core exam skill. They appear in almost every GCSE Computer Science paper in some form, either as a question where you complete the table, or as a question where you write the final output. Either way, the underlying skill is the same: follow the code one line at a time and record what changes.
How to complete a trace table
x = 5
y = 3
x = x + y
y = x - y
print(x, y)
Work through each line and record every change. Only write a new value in a cell when that variable actually changes โ leave the rest blank.
| Line | x | y | Output |
|---|---|---|---|
| x = 5 | 5 | ||
| y = 3 | 3 | ||
| x = x + y | 8 | ||
| y = x - y | 5 | ||
| print(x, y) | 8 5 |
Notice that on line 4, y = x - y uses the new value of x (which is now 8, not 5) and the current value of y (which is still 3). The trace table makes this explicit. This is the kind of detail that is easy to get wrong in your head and easy to get right on a trace table.
Trace tables with loops
total = 0
for i in range(1, 5):
total = total + i
print(total)
With a loop, add one row per iteration. The loop variable (i) changes on each pass, and any variable updated inside the loop needs a new entry each time.
| Iteration | i | total | Output |
|---|---|---|---|
| Start | 0 | ||
| 1 | 1 | 1 | |
| 2 | 2 | 3 | |
| 3 | 3 | 6 | |
| 4 | 4 | 10 | |
| After loop | 10 |
range(1, 5) gives four values: 1, 2, 3, 4. Each iteration adds i to total. The final value of total is 10. print(total) runs once after the loop ends โ not inside it โ so the output row sits at the bottom. Getting the number of iterations right and keeping track of which lines are inside the loop are the two things that produce most errors on this type of question.
What examiners actually test
Trace table questions on GCSE papers nearly always involve one of three scenarios: a short sequence of assignments (often with variable swapping), a loop accumulating a value, or a conditional inside a loop. In every case, the mark scheme rewards correct intermediate values โ not just the final output. That means you must show your working. Writing the right answer with the wrong table gets partial marks at best. Write the right table, even if you are not certain about the output, and you will pick up most of the available marks.
Want structured Python lessons? Python Coach covers 27 lessons and 195 challenges โ free 60 teaching day trial.
Start learning →