Community resourceWorksheet

OCR H446 2.2.1 Tracing and debugging control flow

Part 2 of 14 · H446 2.2.1 · Programming techniques

Faults that appear only at particular input sizes are the ones students find hardest to explain. Sitting in H446 2.2.1, this worksheet turns execution into visible state, so students trace combined control flow, name the observable effect of an off-by-one condition and prove a repair with boundary tests.

Students will:

  • construct a trace of combined selection and iteration in execution order
  • recognise an off-by-one fault in a Python range and state what it causes
  • identify a faulty boundary condition, explain its effect and give a corrected version
  • repair a counting function so it terminates with the required result
  • write a fresh algorithm to a stated specification and justify the test values chosen

Inside: 8 explanation cells, 1 multiple-choice question, 1 fill-in-the-blanks cell, 2 written answers, 3 Python tasks and 1 trace table. 19 marks, about 25 to 35 minutes.

Series: H446 2.2.1 · Programming techniques, part 2 of 14.

Shared by Coding PathwayVerified teacher

  • 16 cells
  • About 30 minutes
  • CC BY-SA 4.0
  • Shared 31 Aug 2026
  • Updated 3 Sept 2026

Preview

The whole resource, exactly as a class sees it. Answers and marking are held back.

Tracing and debugging control flow

A multiplayer lobby fails only at particular team sizes. Tracing turns execution into visible state; boundary tests target the points where behaviour changes.

By the end, you will be able to

  • construct a trace in execution order
  • identify off-by-one, boundary and initialisation faults
  • separate fault, effect and correction
  • test zero, boundary and ordinary paths

Reactivate: selection and loop behaviour from PT01.

Worked debugging model

Faulty condition: size >= 2 AND size < 6. Requirement: accept 2 through 6 inclusive.

  1. Identify: size < 6.
  2. Effect: input 6 follows the reject path.
  3. Correct: size <= 6.
  4. Prove: tests 1, 2, 6 and 7 cover just below, both boundaries and just above.

A correction without its effect is weaker evidence. A typical input such as 4 cannot reveal the upper-bound error.

Worked trace method

For total = 0 followed by for value = 1 to 3, make one row per iteration. Record only a changed value: total becomes 1, then 3, then 6. The loop ends after value 3 because OCR ERL includes both FOR bounds.

When debugging, use the same state evidence in three steps: identify the faulty expression → state its observable effect at a revealing input → give a correction and recheck that input. Naming a line without its effect is incomplete.

Trace table5 marks

Trace the correct OCR ERL algorithm.

Enter a value only when it changes. Keep the listing's order.

Use one row for each pass through the loop. Fill in a box only when that value changes on that row, and leave the rest blank.

AlgorithmExam reference language
  1. score = 0
  2. for round = 1 to 3
  3. if round == 2 then
  4. score = score + 5
  5. else
  6. score = score + 2
  7. endif
  8. next round
  9. print(score)
Trace table with 4 columns
Rowscoreroundround == 2Output
1
2
3
4
5
6
7
Multiple choice1 mark

Python code uses for player in range(1, team_size): but must process players numbered 1 through team_size. What is the fault?

  • AThe loop never starts
  • BPlayer 1 is processed twice
  • CThe final player is omitted
  • Dteam_size becomes zero

Identify, explain, correct

The function should accept team sizes from 2 to 6 inclusive. It currently rejects 6. Do not stop at naming the line: explain the observable effect and repair it.

Worked example
def valid_team(size):
    if size >= 2 and size < 6:
        return True
    return False

print(valid_team(6))
Written answer3 marks

Identify the faulty condition, explain its effect at the boundary and give a corrected condition.

Answer all three demands.

Students type their answer here.

Repair a turn counter

The function must return the number of turns needed to reduce remaining to zero. Each turn removes up to step items. Inputs satisfy remaining >= 0 and step > 0.

Coding task4 marks
def turns_needed(remaining, step):
    turns = 0
    while remaining > step:
        remaining = remaining - step
    return turns

Independent control-flow task

Now write a fresh algorithm rather than repairing one. Return the sum of all even round numbers from 1 through rounds, inclusive. If rounds is 0, return 0.

Coding task5 marks
def even_round_total(rounds):
    pass
Written answer2 marks

Explain why tracing with the boundary values 0 and 6 is more useful here than testing only the value 4.

Link each test to a distinct path or comparison.

Students type their answer here.

Checkpoint

Complete the debugging routine from memory. There is no answer bank, and correctness is withheld until teacher review.

Fill in the blanks4 marks
When a loop omits or adds one repetition, it has an checkpoint gap 1 error. A counter should be checkpoint gap 2 before use and checkpoint gap 3 so that the loop can terminate. Minimum and maximum inputs are checkpoint gap 4 cases.

Review your understanding

Before submitting, check that you can explain the main distinction in your own words, apply it in an unfamiliar context and justify the resulting behaviour or consequence.