Debugging with a trace table

About this lesson: Debugging with a trace table

In short

This program should output the average of 6, 9 and 3, which is 6. Step through and fill the trace table. Compare each value of total with what it should be.

Debugging with a trace table

What you'll explore

Something's wrong: Trace and compare
This program should output the average of 6, 9 and 3, which is 6. Step through and fill the trace table.
Fix and retrace: Check every row
Line 4 overwrote total instead of adding to it. With the fix, total builds up 6, 15, 18. Retrace to check every row matches.
Practise: Find the first wrong row
Run the buggy version once more. The first row where total differs from the expected value tells you which line to look at.
Check yourself: Read the trace
A trace table shows total = 5, then 7, then 2. The inputs were 5, 2 and 2, and total should be the running sum.

Also in this lesson

  • Common mix-ups
  • The bug
  • Bug hunt

Words to know

trace table
A table of values at each step of a program.
expected value
What a variable should be.
logic error
A mistake that gives wrong results without crashing.
debug
Find and fix errors.
overwrite
Replace a variable's value.

Sources

  • BBC Bitesize KS3 Computer Science
  • Raspberry Pi Foundation, Computing curriculum resources

An interactive lesson with a live experiment: move the sliders, press the buttons and answer quick questions. 4 short steps and a 6-question quiz. Part of the Family plan. Written and checked by Shalo Lab. Last updated 11 November 2026.

← Three kinds of error · Prototypes, feedback and better designs →

All lessons in Term 2 · Computing · Age 13