Community resourceWorksheet
OCR H446 1.2.3 Writing, following and using algorithms
Part 4 of 6 · H446 1.2.3 · Software development
The algorithm strand of H446 1.2.3 rewards preserved logic rather than perfect syntax, since coherent pseudocode or program code is accepted. Students here follow state through a trace, use a supplied helper function instead of rewriting it, repair a broken call, and then construct algorithms that include every required input, returned value and file effect.
Students will:
- trace an algorithm and record how each variable changes on every iteration
- explain the relationship between a returned value and the variable that stores it
- call a supplied function correctly rather than duplicating its rules
- complete runnable Python that uses a helper and returns the required list
- write an algorithm that covers ordered file effects such as appending and closing
Inside: 8 explanation cells, 1 multiple-choice question, 2 fill-in-the-blanks cells, 4 written answers, 1 Python task and 1 trace table. 35 marks, about 50 to 65 minutes.
Series: H446 1.2.3 · Software development, part 4 of 6.
Shared by Coding PathwayVerified teacher
- 17 cells
- About 60 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.
Writing, following and using algorithms
OCR accepts coherent pseudocode or program code and does not require perfect pseudocode syntax. The hard work is preserving logic: follow state in order, respect supplied interfaces and include every required input, structure, returned value and side effect.
Read before you write
Before following or extending an algorithm, create an interface ledger:
- What values enter?
- Which variables can change?
- Which conditions choose a path?
- Does a helper print, return, or change external state?
- What must the main algorithm store, output or write?
Calling a supplied helper is not the same as rewriting it. A returned value must be captured or used.
Worked follow: state, path and result
def adjusted_total(values, limit):
total = 0
for value in values:
if value <= limit:
total = total + value
else:
total = total + limit
return total
print(adjusted_total([3, 8, 5], 6))
State route: total 0 → 3 → 9 (8 is capped to 6) → 14 → return 14 → print 14. Following means executing the supplied conditions with the supplied data, not describing what the function probably does.
Trace the function for values [4, 9, 2] and limit 5. Record value, total, the condition result and final output.
Enter a value only when it changes. Record returned and printed values in order.
Use one row for each statement as it runs. Fill in a box only when that value changes on that row, and leave the rest blank.
def adjusted_total(values, limit):total = 0for value in values:if value <= limit:total = total + valueelse:total = total + limitreturn totalprint(adjusted_total([4, 9, 2], 5))
| Row | values (adjusted_total) | limit (adjusted_total) | total (adjusted_total) | value (adjusted_total) | Return value | value <= limit | Output |
|---|---|---|---|---|---|---|---|
| 1 | |||||||
| 2 | |||||||
| 3 | |||||||
| 4 | |||||||
| 5 | |||||||
| 6 | |||||||
| 7 | |||||||
| 8 | |||||||
| 9 | |||||||
| 10 | |||||||
| 11 | |||||||
| 12 | |||||||
| 13 | |||||||
| 14 | |||||||
| 15 |
A function executes return status and the caller stores result = functionName(value). Which statement is accurate?
- AThe function must be rewritten inside the caller
- BReturn and print always have identical effects
- CThe parameter is ignored because result has a different name
- DThe returned value is assigned to result; it is not automatically printed
Explain why the trace adds 5 rather than 9 on the second iteration and state the final returned value.
Refer to the condition, selected branch and accumulated state.
Students type their answer here.
Use a supplied helper
function classifyLevel(reading)
if reading < 20 then
return 'LOW'
elseif reading <= 70 then
return 'NORMAL'
else
return 'HIGH'
endif
endfunction
Requirement: input a reading, call classifyLevel, store its return value in label, then output both reading and label.
reading = input('Reading')
label = classifyLevel(reading)
output(reading)
output(label)
The main algorithm uses the interface. It neither copies the three-way selection nor assumes the helper prints.
- input
- argument
- value
- methodology
A student writes classifyLevel(reading) on a line by itself, then outputs label, which was never assigned. Repair the algorithm and explain the error.
Use one corrected assignment and distinguish a call from capturing its return.
Students type their answer here.
Apply the model independently
The remaining tasks change the context or reduce the support. Complete them without copying the worked model, then check that each explanation connects a mechanism to its consequence.
Runnable construction: use, do not replace
The supplied classify_level function is complete. Finish flag_readings: call the helper for every reading, append only the non-NORMAL labels and return the list. Do not duplicate the helper's thresholds.
def classify_level(reading):
if reading < 20:
return "LOW"
if reading <= 70:
return "NORMAL"
return "HIGH"
def flag_readings(readings):
# Call classify_level for each item. Return labels that are not NORMAL.
passRequirements ledger: ordered file side effects
Task: input reading; call the supplied function; store the label; open log.txt for appending; write the reading and label; close the file.
A requirements ledger prevents omission:
| Demand | Evidence in algorithm |
|---|---|
| input | assignment from input |
| supplied helper | call with reading |
| return | label receives call result |
| persistent output | open → write reading → write label → close |
The exact spelling of file operations may vary by coherent language. Their order and purpose do not.
Write coherent pseudocode or program code for the log task. The helper classifyLevel(reading) already exists and must be used. Store each record as reading,label on one line.
Check every demand: input, call, captured return, append mode, both values in one record, close. Do not rewrite classifyLevel.
Students type their answer here.
A solution gets the correct label but never closes the file and writes only the label. Explain why a correct classification is not a complete algorithm for the task.
Compare the observed behaviour with the requirements ledger.
Students type their answer here.
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 each consequence rather than only naming a feature.