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

Use a supplied component through its interfaceread the interface before writing more codesupplied helper: classifyLevel(reading)parameter in: one integer readingreturn out: one text label1 inputreading2 call helperwith reading3 capturereturned label4 writeboth values5 closefileRewriting the helper does not satisfy the call requirement.A printed value is not automatically a returned value; a return must be captured or used.

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 table13 marks

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.

ProgramPython
  1. def adjusted_total(values, limit):
  2. total = 0
  3. for value in values:
  4. if value <= limit:
  5. total = total + value
  6. else:
  7. total = total + limit
  8. return total
  9. print(adjusted_total([4, 9, 2], 5))
Trace table with 7 columns
Rowvalues (adjusted_total)limit (adjusted_total)total (adjusted_total)value (adjusted_total)Return valuevalue <= limitOutput
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Multiple choice1 mark

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
Written answer4 marks

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.

Fill in the blanks3 marks
The caller first obtains the gap 1, passes it as an gap 2, captures the returned gap 3, then performs the required output.
  • input
  • argument
  • value
  • methodology
Written answer4 marks

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.

Coding task7 marks
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.
    pass

Requirements 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:

DemandEvidence in algorithm
inputassignment from input
supplied helpercall with reading
returnlabel receives call result
persistent outputopen → write reading → write label → close

The exact spelling of file operations may vary by coherent language. Their order and purpose do not.

Written answer8 marks

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.

Written answer4 marks

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.

Fill in the blanks4 marks
To follow an algorithm, update state in execution checkpoint gap 1. A function checkpoint gap 2 passes a value back to its caller. The caller must capture or use it. Exact pseudocode checkpoint gap 3 is less important than coherent logic and appropriate code checkpoint gap 4.

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.