Community resourceWorksheet
1CP2-CT-8.1 Formal trace tables and variable state
Part 1 of 5 · 1CP2-CT-8 · Tracing, debugging, sorting and searching
A trace table records how an algorithm's state changes while it runs. Examiners use traces to check that you can follow sequence, selection and iteration systematically. A trace is evidence, not a guess at the final output.
Students will:
- record changing state, conditions and output in execution order
- complete a formal trace without treating blanks as zero
- distinguish a stored value from printed output
- explain evidence from a trace precisely
Inside: 6 explanation cells, 1 fill-in-the-blanks cell, 3 multiple-choice questions, 3 written answers and 1 trace table. 12 marks, about 45 minutes.
Series: 1CP2-CT-8 · Tracing, debugging, sorting and searching, part 1 of 5.
Shared by Coding PathwayVerified teacher
- 14 cells
- About 45 minutes
- CC BY-SA 4.0
- Shared 17 Aug 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
Formal trace tables and variable state
A trace table records how an algorithm's state changes while it runs. Examiners use traces to check that you can follow sequence, selection and iteration systematically. A trace is evidence, not a guess at the final output.
1. One row records one meaningful step
For an iteration trace, complete one row for each loop pass. Write a variable only when its value changes. Record a condition as True or False when it is tested, and record text in the output column only when print executes. A blank means unchanged; it never means zero.
print is gap 2. An empty trace cell normally means the value is gap 3.- output
- state
- unchanged
- zero
2. Worked trace
total = 0
for value in [2, 5, 1]:
total = total + value
if total > 5:
print(total)
After the three passes, total is 2, then 7, then 8. The condition is false, true, true. Output occurs only on the last two passes: 7 then 8. The final value 8 and the two printed values are related, but they are not the same record.
A variable did not change during one loop pass. What belongs in its trace cell when the instructions say blank means unchanged?
- A0
- BA blank
- CThe variable name
- DFalse
A student writes 0 in every unused trace cell. Explain why this makes the trace inaccurate.
Refer to assignment and unchanged state.
Students type their answer here.
3. Trace nested selection carefully
For each item, first update count, then test the condition, then update score only if the condition is true. Indentation shows that the if body belongs inside the loop. Never apply the if only once after all iterations.
Complete the trace table for the algorithm.
Use one row per iteration. Leave a cell blank when its value is unchanged.
Use one row for each pass through the loop. Fill in a box only when that value changes on that row, and leave the rest blank.
score = 1count = 0for item in [4, 7, 3]:count = count + 1if item > 4:score = score + itemprint(score)
| Row | score | count | item | item > 4 | Output |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 | |||||
| 6 | |||||
| 7 |
4. Commit to a prediction
Read this code without running it.
value = 3
for step in range(2):
value = value * 2
print(value)
What exact value is printed?
- A6
- B9
- C12
- D18
Explain how the program reaches its output.
State the value after each loop pass.
Students type their answer here.
In the worked trace, what value is held in total immediately after the second addition, and what has been printed by that point?
Keep current state and output separate.
Students type their answer here.
Which habit gives the most reliable trace?
- AGuess the final print and work backwards
- BExecute each indented statement in order for every iteration
- CPut every variable on every row even when unchanged
- DTreat blanks as zero
Route forward
You can now separate state, conditions and output in a formal trace. Next you will use trace evidence, error messages and focused tests to diagnose and repair programs.