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, 3 fill-in-the-blanks cells, 4 written answers, 1 Python task and 1 trace table. 39 marks, about 50 to 65 minutes.

Series: H446 1.2.3 · Software development, part 4 of 6.

Shared by Coding PathwayVerified teacher

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

Preview

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

Writing, following and using algorithms

An algorithm is a sequence of steps that solves a problem or completes a task. At A Level, you must be able to follow algorithms and write them using coherent pseudocode or program code. Perfect OCR-style syntax is not required, but the logic must be clear and complete.

This worksheet practises sequence, selection, iteration, changing variable values, function calls, returned values and file operations.

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, identify:

  • the input values;
  • the variables that can change;
  • the conditions and loops that control the route;
  • the parameters passed into any supplied function;
  • the value returned by that function;
  • every value that must be output or written to a file.

If a function is supplied, call it through its stated interface. Do not replace it with copied code. Store or use any returned value required by the task.

Worked example: follow the values in order

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))

Follow each iteration rather than guessing the purpose of the function:

  • start with total = 0;
  • add 3, so total = 3;
  • 8 is greater than the limit, so add 6 and make total = 9;
  • add 5, so total = 14;
  • return 14 to the call, which is then printed.

A trace records the route through the conditions as well as the final answer.

Fill in the blanks4 marks
Complete the algorithm so that it counts values greater than limit. count = 0 for index in range(0, gap 1): if values[gap 2] > limit: count = gap 3 return gap 4
  • len(values)
  • index
  • count + 1
  • count
  • limit
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 algorithm adds 5 instead of 9 during the second iteration of the trace. State the final value returned by the function.

Use the current value, the condition result, the selected branch and the new total.

Students type their answer here.

Use a function that has already been supplied

function classifyLevel(reading)
    if reading < 20 then
        return 'LOW'
    elseif reading <= 70 then
        return 'NORMAL'
    else
        return 'HIGH'
    endif
endfunction

The task says: input a reading, call classifyLevel, store the returned value in label, and output the reading and label.

reading = input('Reading')
label = classifyLevel(reading)
output(reading)
output(label)

The main algorithm calls the supplied function. It does not copy the function's selection statements. return passes a value back to the calling expression; it does not automatically print that value.

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 and then outputs label, although label has not been assigned. Correct the algorithm and explain the mistake.

Show how the returned value is stored, then explain why the original line did not define `label`.

Students type their answer here.

Construct and check complete algorithms

The remaining tasks remove some support. Before submitting each solution, check the inputs, loop or selection, function call, returned value, outputs and file operations against the exact task.

Runnable task: call the supplied function

The function classify_level is complete. Finish flag_readings so that it calls the function for every reading, stores each returned label and adds only non-NORMAL labels to the result list. Do not copy the thresholds into flag_readings.

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

Check every required file operation

Task: input a reading; call the supplied function; store the returned label; open log.txt for appending; write the reading and label; close the file.

RequirementEvidence needed in the algorithm
obtain the dataassign the input to reading
use the supplied functioncall it with reading
keep its resultassign the returned value to label
save a complete recordopen → write reading,label → close

The precise commands may differ between pseudocode and programming languages. The required actions and their order must still be present.

Written answer8 marks

Write coherent pseudocode or program code for the log task. The function classifyLevel(reading) already exists and must be called. Append one record containing both the reading and label to log.txt, then close the file.

Check for input, function call, stored return, append mode, a complete record and close. Do not rewrite the supplied function.

Students type their answer here.

Written answer4 marks

A solution calculates the correct label but writes only the label to the file and never closes the file. Explain why it does not fully meet the task.

Compare what the solution does with every required action in the task.

Students type their answer here.

Fill in the blanks4 marks
To follow an algorithm, update each variable in execution checkpoint gap 1. A function uses checkpoint gap 2 to pass a value back to its caller. The caller must store or use that value. Exact pseudocode checkpoint gap 3 is less important than clear logic and appropriate control checkpoint gap 4.

Review your understanding

Check that you can trace every changed value, evaluate each condition, call a supplied function without rewriting it, use its returned value and include every required file action in the correct order.