Community resourceWorksheet

J277 2.1.2 Completing, correcting and refining algorithms

Part 1 of 3 · J277 2.1.2 · Tracing and refining algorithms

The OCR question types that hand students an algorithm to complete, correct or refine.

Students will:

  • work from the stated purpose and test data rather than guessing
  • complete missing statements in an algorithm
  • find and correct a logic error in an accumulator
  • validate an inclusive range correctly
  • refine an algorithm to meet a new requirement

Inside: 7 explanation cells, 3 runnable Python tasks, 2 multiple-choice questions, 1 fill-in-the-blanks cell and 2 written answers. 23 marks, about 60 minutes.

Series: J277 2.1.2 · Tracing and refining algorithms, part 1 of 3.

Shared by Coding PathwayVerified teacher

  • 15 cells
  • About 60 minutes
  • CC BY-SA 4.0
  • Shared 17 Aug 2026
  • Updated 9 Sept 2026

Preview

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

Completing, correcting and refining algorithms

OCR questions may ask you to complete missing statements, identify and correct errors, or refine an algorithm for a new requirement. Work from the stated purpose and test data, rather than changing code at random.

A disciplined correction method

  1. State the intended result.
  2. Trace the current code using the supplied or chosen test data.
  3. Locate the first point where the actual state differs from the expected state.
  4. Make the smallest relevant correction.
  5. Re-test with representative values, values exactly at important limits and, where relevant, values the program should reject.

A syntax error breaks the grammatical rules of the programming language and stops the program being run or translated. A logic error allows execution but produces unexpected output or behaviour.

Multiple choice1 mark

A program runs but gives the wrong total because it subtracts instead of adding. What type of error is this?

  • ASyntax error
  • BHardware error
  • CLogic error
  • DNo error
Fill in the blanks2 marks
A missing colon is usually a label 1 error. Using > instead of >= at a boundary is a label 2 error.
  • syntax
  • logic
  • decomposition
  • abstraction

Debugging task: repair an accumulator

The next program should calculate the total and average of four scores. It runs, but the statement inside the loop replaces total with the current score instead of adding the score to the running total.

Make the smallest relevant correction, then run and check that total becomes 64 and average becomes 16.0. Do not replace the results with fixed answers; the loop must perform the accumulation.

Coding task3 marks
# Correct the program so it calculates the average of all four scores.
scores = [10, 14, 18, 22]
total = 0
for score in scores:
    total = score
average = total / len(scores)

Completion task: validate an inclusive range

Complete the missing selection so that valid becomes True for values from 1 to 10 inclusive. It should remain False for values outside that range.

Use both boundary comparisons joined by the correct Boolean operator. The supplied value is the upper boundary, so an exclusive < 10 comparison would fail.

Coding task3 marks
# Complete the missing selection so values from 1 to 10 inclusive are valid.
value = 10
valid = False
# Write the decision here.
Multiple choice1 mark

Which test data is most useful for exposing an error in a rule that should accept ages 13 to 18 inclusive?

  • A15 only
  • BA name
  • C1000 only
  • D13 and 18

Refinement task: add a two-part discount rule

Refine the supplied program for this new requirement: members receive 10% off only when the original total is at least £20.

Use one decision that checks both requirements. Leave final_total unchanged when either requirement is false; otherwise store 90% of total. The checks will try a qualifying member, a non-member and a member below the threshold.

Coding task3 marks
# Refine the discount algorithm.
# New rule: members receive 10% off only when total is at least £20.
total = 30.0
member = True
final_total = total
# Add the required decision.
Written answer6 marks

For the refined discount program, give three tests: a member with a total above £20, a member with a total exactly equal to £20, and a case that should not receive a discount. State the expected result of each.

Give the member value, original total and expected final total for each case.

Students type their answer here.

Correcting a represented algorithm

The flowchart is intended to input a score, output Pass for scores of 50 or more and output Review otherwise. Its underlying decision is sensible, but two parts of its notation need correcting.

A flowchart containing two notation faults Start leads to a rectangle labelled Input score and then to a decision asking whether score is at least 50. The left path is labelled True and outputs Pass. The right path has no label and outputs Review. Both paths lead to End. Start Input score score ≥ 50? decision True Output “Pass” Output “Review” End

Compare the diagram with the flowchart conventions introduced earlier. Focus on the symbol used to receive data and the labels that show the results of a decision.

Written answer4 marks

The faulty flowchart above is meant to input a score, output Pass for scores of 50 or more and output Review otherwise. Identify two faults in its notation and explain how each should be corrected.

Inspect both the shape used for input and the labels on the two decision paths. Give the fault and its correction for each.

Students type their answer here.

Review

Completion, correction and refinement all begin with the required behaviour. Trace the current state, locate the first mismatch, make a focused change and re-test representative values and exact limits. OCR awards credit for precise corrections, so identify both the faulty statement and the effect of your fix.