All subjects · Computer Science · WCP02 Practical Programming and Problem-solving
Testing, debugging, reviewing and refining
Edexcel IAL Computer Science · WCP02 Practical Programming and Problem-solving
Ensuring code fits its purpose means testing it methodically, finding and fixing errors, and then improving it. The first question of the sample paper was a program full of errors to fix.
Types of error (spec 9.3.1)
| Error | What happens | Example |
|---|---|---|
| Syntax error | The code breaks Python's rules and will not run at all | missing colon after if; unclosed bracket; wrong indentation |
| Runtime error (exception) | The program starts but crashes on a line | TypeError, NameError, UnboundLocalError, IndexError, ZeroDivisionError |
| Logic error | The program runs but gives the wrong result | < instead of <=; wrong index such as top + 1; total reset inside a loop |
Test data
Plan tests before running them, with the expected result for each:
- Normal data: typical valid values.
- Boundary data: values at the edges of the valid range and just outside.
- Erroneous data: wrong type or clearly invalid values, which should be rejected without crashing.
Compare actual results with expected results; any difference is a bug to fix.
Debugging techniques
- Read the error message: it names the exception and the line number.
- Add temporary print() statements to show variables at key points.
- Use the IDE debugger: set a breakpoint, step through line by line and watch variables.
- Dry run with a trace table: one column per variable, one row per change.
n = 5
f = 1
while n > 1:
f = f * n
n = n - 1
print("n =", n, "f =", f)Output:
n = 4 f = 5
n = 3 f = 20
n = 2 f = 60
n = 1 f = 120| n | f |
|---|---|
| 5 | 1 |
| 4 | 5 |
| 3 | 20 |
| 2 | 60 |
| 1 | 120 |
Trace table for the loop above (first row: before the loop)
Reviewing and refining
Once it works, review the code against the task: does it meet every requirement, handle every case, and is the output formatted as asked? Then refine it: remove repetition into subprograms, replace literals with constants, improve names and comments, and reduce the number of passes. Re-test after every change. In the exam, do not add features that were not asked for.
Worked example
A program should accept ages 11 to 18. Plan normal, boundary and erroneous test data.
- Normal: 14, accept
- Boundary: 11 and 18, accept; 10 and 19, reject
- Erroneous: "twelve", rejected with a message, no crash
Answer: Normal 14; boundary 10, 11, 18, 19; erroneous "twelve"
Check yourself
- A program runs without crashing but calculates an average that is always slightly too high. What kind of error is this?
- Syntax error
- Runtime error
- Logic error
- Type conversion error
Show answer
Logic error. It runs and finishes, so it is not a syntax or runtime error; the result is wrong, so it is a logic error.
- Which line contains a syntax error?
- if total > 10
- total = total + 1
- print("Total:", total)
- while total < 10:
Show answer
if total > 10. An if statement must end with a colon.
- A program accepts quantities from 1 to 50. What type of test data is 50?
- Normal
- Erroneous
- Boundary
- Extreme invalid
Show answer
Boundary. 50 is the largest valid value, at the edge of the range.
- What is displayed when this code runs?
```python
a = 1
b = 1
for i in range(4):
a, b = b, a + b
print(a, b)
```
Show answer
5 8. Trace (a, b): (1, 1), (1, 2), (2, 3), (3, 5), (5, 8): 5 8.
- This code should display 9 but it does not. Which line number contains the error?
```
1 values = [9, 2, 6, 1]
2 largest = 0
3 for i in range(1, len(values)):
4 if values[i] > largest:
5 largest = values[i]
6 print(largest)
```
Show answer
3. The loop starts at index 1, so values[0] (9) is never checked. It should be for i in range(0, len(values)):, or simply for i in range(len(values)):.
- In an IDE, what does setting a breakpoint do?
- Deletes the line from the program
- Pauses the program at that line so you can inspect variables and step on
- Stops the program from ever reaching that line
- Converts the line into a comment
Show answer
Pauses the program at that line so you can inspect variables and step on. A breakpoint pauses execution so you can watch variables and step through the following lines.
Sources
- Pearson Edexcel International Advanced Subsidiary/Advanced Level in Computer Science specification (XCP01/YCP01), first teaching 2026
- Pearson IAL Computer Science Unit 2 Programming Language Subset (PLS), Python 3
- Pearson IAL Computer Science IAS sample assessment materials (Unit 2 paper and mark scheme)
Last updated 8 November 2026. Spotted a mistake? Tell us.