Finding and fixing errors: trace tables

Every programmer makes mistakes. Good programmers know how to find them. Learn the main kinds of error and how a trace table helps you spot them.

Practise this lesson free (6 questions)

Three kinds of error

ErrorWhat happensExample
Syntax errorPython cannot understand the code, so it will not runa missing colon or bracket, or a spelling mistake such as pritn
Runtime errorthe program starts but crashes while runningdividing by zero, or int("hello")
Logic errorthe program runs but gives the wrong answerusing + when you meant *

Spot the error

total = 0
for n in range(1, 4)
    total = total + n
print(total)
This has a syntax error: the for line is missing its colon.
length = 5
width = 3
area = length + width
print(area)
This runs and prints 8, but the area should be 5 × 3 = 15. It is a logic error: + should be *.

Trace tables

A trace table records the value of each variable as the program runs, one row per change.
x = 2
for i in range(3):
    x = x * 2
print(x)
The loop runs 3 times, so x doubles 3 times. Output: 16
Stepix
start2
104
218
3216
Worked example

Complete a trace table for this program and give the output.
a = 10
b = 3
while a > b:
    a = a - b
print(a)

  1. Each row shows a and whether a > b is still True.
  2. a = 10, a > b is True
  3. a = 7, a > b is True
  4. a = 4, a > b is True
  5. a = 1, a > b is False
  6. The loop stops when a > b is False.

Answer: 1

Key idea

Syntax errors stop a program running, runtime errors crash it part way, and logic errors give wrong answers. A trace table tracks each variable step by step to find logic errors.

Key words
AND
A Boolean operator that gives True (1) only when both inputs are True.
Trace table
A table that records the value of each variable, line by line, as you work through a program by hand.
Program
A set of instructions written in a programming language that a computer can run.
Variable
A named store in memory that holds a value, which can change while the program runs.
Syntax error
A mistake in the rules of the language, such as a missing colon or bracket, so the program cannot run.

All KS3 Computing key terms and definitions →

Quick check

Try two quick questions

See if it has sunk in. Answers are marked straight away.

Extra practice

2 more questions

Try each one, then tap to check.

  1. A program runs but says the average of 4 and 6 is 7. What kind of error is this?

    1. Syntax error
    2. Logic error
    3. Runtime error
    4. Hardware error
    Show the answer

    Answer: Logic error

    Wrong answer, no crash: logic error.

  2. Python will not run a program because a colon is missing. What kind of error is this?

    1. Logic error
    2. Syntax error
    3. Runtime error
    4. Overflow error
    Show the answer

    Answer: Syntax error

    Breaking the language rules is a syntax error.

Check you have got it

Answer 6 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.

Video for this lesson coming soon. Subscribe on YouTube

Sources and references

Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.

Related lessons