Community resourceWorksheet

1CP2-CT-8.2 Diagnosing and correcting program errors

Part 2 of 5 · 1CP2-CT-8 · Tracing, debugging, sorting and searching

A syntax error breaks the language rules, so the code cannot be translated or started normally. A runtime error occurs while syntactically valid code executes an operation that cannot be completed. A logic error allows the program to run but produces incorrect behaviour. Runtime does not mean ‘slow’.

Students will:

  • distinguish syntax, runtime and logic errors from evidence
  • locate and explain a boundary fault
  • amend a program rather than only naming its error
  • choose tests that demonstrate the repair

Inside: 7 explanation cells, 1 fill-in-the-blanks cell, 3 multiple-choice questions, 3 written answers and 1 Python task. 18 marks, about 45 minutes.

Series: 1CP2-CT-8 · Tracing, debugging, sorting and searching, part 2 of 5.

Shared by Coding PathwayVerified teacher

  • 15 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.

Diagnosing and correcting program errors

A syntax error breaks the language rules, so the code cannot be translated or started normally. A runtime error occurs while syntactically valid code executes an operation that cannot be completed. A logic error allows the program to run but produces incorrect behaviour. Runtime does not mean ‘slow’.

1. Debug from evidence

Evidence-led debugging cycleobservelocatereasonamendretestOne passing input is not proof: keep tests that expose boundaries and earlier behaviour.

Use an error message, unexpected output, a trace and focused test data to narrow the cause. After changing code, rerun the test that exposed the fault and regression tests that protect earlier working behaviour.

Fill in the blanks3 marks
A missing colon is usually a gap 1 error. Division by zero during execution is a gap 2 error. Using > instead of >= at a boundary is a gap 3 error when the program still runs.
  • logic
  • runtime
  • syntax
Multiple choice1 mark

Which is the most precise definition of a runtime error?

  • AA program takes longer than expected
  • BAn operation cannot be completed while otherwise valid code is executing
  • CThe programmer dislikes the output
  • DA comment contains a spelling mistake

2. Model a boundary fault

A ticket is free for ages 5 and under. The condition if age < 5: wrongly charges a five-year-old. This is a logic error: the program runs, but the inclusive boundary is missing. Change it to age <= 5, then retest ages 4, 5 and 6.

Read this faulty code without running it.

scores = [10, 12, 8]
total = 0
for position in range(1, len(scores)):
    total = total + scores[position]
print(total)
Multiple choice1 mark

What value does the faulty program print?

  • A18
  • B20
  • C30
  • D32
Written answer3 marks

Explain why the result is wrong and state the required correction.

Refer to the starting position and all three list items.

Students type their answer here.

3. Choose tests that prove the repair

A good test has input, an expected result and a reason. Normal data checks typical behaviour. Boundary data checks the exact edge of a condition. Erroneous data checks data that should be rejected. One successful normal input cannot prove that a boundary was repaired.

Written answer3 marks

For the ‘age 5 and under’ rule, give three test ages and expected outcomes that would check below, at and above the boundary.

Use ages immediately around 5.

Students type their answer here.

4. Amend and retest

The function should return the number of values at least the limit. Repair the logic, keeping the parameterised function and returned result.

Coding task4 marks
def count_at_least(values, limit):
    count = 0
    for value in values:
        if value > limit:  # fault
            count = count + 1
    return count

result = count_at_least([4, 5, 8, 3], 5)
print(result)
Written answer2 marks

After the correction, explain why testing only [5] is insufficient. Give one additional useful test and expected result.

Protect a different part of the behaviour.

Students type their answer here.

Multiple choice1 mark

A corrected program passes the one input that originally failed. What should happen next?

  • ADelete all tests
  • BRun boundary, normal and relevant earlier tests
  • CAssume every path is correct
  • DRename the logic error as syntax

Route forward

You can classify errors precisely and repair from evidence. The next two worksheets apply tracing and amendment to the standard bubble sort and binary search algorithms.