Community resourceWorksheet

1CP2-CT-9.3 Files strings lists and subprograms integrated solution

Part 3 of 4 · 1CP2-CT-9 · Testing, structures and integrated solutions

Integrated programs are easier to reason about when decomposed. This worksheet uses a fictional CSV schema name,score, for example Asha,17. File input produces strings, so numeric score text must be converted before arithmetic or comparison.

Students will:

  • follow data from a CSV file into converted list values
  • decompose processing into a focused subprogram
  • calculate and return a result from supplied records
  • design tests for the integrated solution

Inside: 5 explanation cells, 1 fill-in-the-blanks cell, 3 multiple-choice questions, 3 written answers and 1 Python task. 19 marks, about 45 minutes.

Series: 1CP2-CT-9 · Testing, structures and integrated solutions, part 3 of 4.

Shared by Coding PathwayVerified teacher

  • 13 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.

Files, strings, lists and subprograms: an integrated solution

Integrated programs are easier to reason about when decomposed. This worksheet uses a fictional CSV schema name,score, for example Asha,17. File input produces strings, so numeric score text must be converted before arithmetic or comparison.

1. Model the data pipeline

CSV text → split fields → convert score to integer → store scores in a list → process through a function → format the result. A clean function interface receives required data through parameters and sends a result back with return; it does not depend on hidden globals.

Fill in the blanks3 marks
split(",") produces gap 1 fields. A score field must be converted with gap 2 before addition. A function sends a reusable result with gap 3.
  • int
  • return
  • string
Multiple choice1 mark

Which is the clearest interface for calculating the mean of a list?

  • A`mean_scores()` using an undeclared global
  • B`mean_scores(scores)` returning a number
  • CA procedure that only prints every score
  • DOne function that opens, parses, calculates and displays everything

2. Predict a processing fragment

def count_passes(scores, pass_mark):
    count = 0
    for score in scores:
        if score >= pass_mark:
            count = count + 1
    return count

print(count_passes([12, 18, 20, 9], 18))
Multiple choice1 mark

What exact value is printed?

  • A1
  • B2
  • C3
  • D59
Written answer2 marks

Explain why 18 is counted but 12 is not.

Refer to the operator and parameter.

Students type their answer here.

3. Complete the processing stage

The supplied file scores.csv contains four name,score records. Starter code opens it, reads each line, splits the fields, converts scores to integers and closes the file. Define mean_score(scores) to total the converted list and return the mean. Store the returned result in mean, then print exactly Mean: 15.00.

Coding task6 marks
names = []
scores = []
score_file = open("scores.csv", "r")
line = score_file.readline().strip("\n")
while line != "":
    fields = line.split(",")
    names.append(fields[0])
    scores.append(int(fields[1]))
    line = score_file.readline().strip("\n")
score_file.close()

# Define mean_score, call it and format the result.
Written answer3 marks

Give one normal and one boundary test for count_passes, with expected results.

Include a score exactly equal to the pass mark.

Students type their answer here.

Written answer2 marks

Explain one benefit of keeping calculation inside mean_score instead of placing all statements in the main program.

Use testing, reuse or clarity.

Students type their answer here.

Multiple choice1 mark

What happens if CSV score text such as "18" is added to integer total without conversion?

  • AThe mean is automatically calculated
  • BA runtime type error occurs
  • CThe string becomes zero
  • DThe file is sorted

Route forward

You have combined a file-data model, conversion, list processing, a returned value, formatting and tests. The checkpoint retrieves these decisions with less support.

Data files (1)
  • scores.csv31 B