Community resourceWorksheet

1CP2-CT-7.4 Structured programming problem solving

Part 4 of 5 · 1CP2-CT-7 · Subprograms, scope and libraries

The structured problem-solving worksheet, working from a stated requirement to a tested program built from cohesive functions.

Students will:

  • state the inputs, processes and outputs a requirement implies
  • trace a function call to check it returns what the caller needs
  • explain a boundary result produced by selection inside a function
  • choose a boundary test and say what it checks
  • identify and correct a runtime failure on an empty list

Inside: 7 explanation cells, 2 multiple-choice questions, 1 Python task, 1 trace table and 4 written answers. 17 marks, about 45 minutes.

Series: 1CP2-CT-7 · Subprograms, scope and libraries, part 4 of 5.

Shared by Coding PathwayVerified teacher

  • 15 cells
  • About 45 minutes
  • CC BY-SA 4.0
  • Shared 17 Aug 2026

Preview

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

Structured programming problem solving

A larger programming problem becomes manageable when you identify inputs, outputs, stored data, calculations and decisions, then assign cohesive responsibilities to subprograms. This worksheet models an examination-style route from requirements to a testable program.

1. Analyse the requirement

A charity walk records distances in kilometres. The program must total a list of distances, calculate the mean, count distances at least 5 km and display the mean to two decimal places.

Data: a one-dimensional list of real values. Process: traverse once, accumulate and select. Output: total, mean and count. Decomposition: one function for total, one for count, and main-program formatting.

Written answer3 marks

State the input, two required processes and the outputs for the charity-walk program.

Use the scenario's data and named results.

Students type their answer here.

2. Model one cohesive function

def total_values(values):
    total = 0
    for value in values:
        total = total + value
    return total

The list enters through a parameter, total is local, and one value returns. The function does not ask for input or decide how to display the result, so it is reusable and easy to test.

Trace table6 marks

Trace the total function call.

Record value and total on each pass, then the returned answer.

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.

ProgramPython
  1. def total_values(values):
  2. total = 0
  3. for value in values:
  4. total = total + value
  5. return total
  6. answer = total_values([2.5, 4.0, 3.5])
  7. print(answer)
Trace table with 6 columns
Rowvalues (total_values)total (total_values)value (total_values)answerReturn valueOutput
1
2
3
4
5
6
7
8

3. Check selection inside a function

Read this code without running it.

def count_long(values):
    count = 0
    for value in values:
        if value >= 5:
            count = count + 1
    return count

print(count_long([4.9, 5.0, 7.2, 3.1]))
Multiple choice1 mark

What exact value is printed?

  • A1
  • B2
  • C3
  • D20.2
Written answer2 marks

Explain why 5.0 is counted and 4.9 is not.

Refer to the relational operator and boundary.

Students type their answer here.

4. Complete the integrated program

Create mean_value(values) by calling total_values(values) and dividing by len(values). Return the mean. Use the supplied data, store the result in mean, and print exactly Mean: 5.15. This non-empty list avoids division by zero.

Coding task5 marks
def total_values(values):
    total = 0
    for value in values:
        total = total + value
    return total

distances = [4.5, 6.2, 5.8, 4.1]
# Define mean_value, call it, and format the mean.

5. Test from requirements

A test needs a reason and an expected result. For count_long, normal data checks typical mixed values, boundary data includes exactly 5, and exceptional data could include an empty list if the wider program claims to accept it. If empty input is not allowed, validation should prevent the call before calculating a mean.

Written answer3 marks

Give a boundary test for count_long(values) and its expected result, then explain what it checks.

Include at least one value exactly equal to 5.

Students type their answer here.

Written answer2 marks

The program calculates mean = total / len(values) for an empty list. Identify the runtime problem and describe a robust correction.

Connect list length zero to the division.

Students type their answer here.

Multiple choice1 mark

Why should mean_value return a number rather than only print it?

  • AA returned number can be stored, tested, formatted or used in another calculation.
  • BPrinting makes the list longer.
  • CReturn repeats the function forever.
  • DA function cannot contain arithmetic.

Route forward

You have moved from requirements through decomposition, tracing, construction, formatting and testing. The checkpoint now assesses the series with reduced scaffolding.