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.
Three kinds of error
| Error | What happens | Example |
|---|---|---|
| Syntax error | Python cannot understand the code, so it will not run | a missing colon or bracket, or a spelling mistake such as pritn |
| Runtime error | the program starts but crashes while running | dividing by zero, or int("hello") |
| Logic error | the program runs but gives the wrong answer | using + when you meant * |
Spot the error
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
x = 2
for i in range(3):
x = x * 2
print(x)
| Step | i | x |
|---|---|---|
| start | 2 | |
| 1 | 0 | 4 |
| 2 | 1 | 8 |
| 3 | 2 | 16 |
Complete a trace table for this program and give the output.
a = 10
b = 3
while a > b:
a = a - b
print(a)
- Each row shows a and whether a > b is still True.
- a = 10, a > b is True
- a = 7, a > b is True
- a = 4, a > b is True
- a = 1, a > b is False
- The loop stops when a > b is False.
Answer: 1
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.
- 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.
Try two quick questions
See if it has sunk in. Answers are marked straight away.
2 more questions
Try each one, then tap to check.
A program runs but says the average of 4 and 6 is 7. What kind of error is this?
- Syntax error
- Logic error
- Runtime error
- Hardware error
Show the answer
Answer: Logic error
Wrong answer, no crash: logic error.
Python will not run a program because a colon is missing. What kind of error is this?
- Logic error
- Syntax error
- Runtime error
- 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.
Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.