Bring the parts together
This project combines the course's programming skills in a small results system. You will work with two-dimensional records, validate scores, authenticate a classroom user, calculate a result using a function and write a report. It is an original teaching project, not a reconstruction of an official Pearson starter file.
Allow two sessions. In the first, analyse the requirements and build the record-processing functions with hard-coded test data. In the second, add file input/output, run the test plan and explain your repairs. Keep a working copy before each substantial change so you can locate the cause of a new failure.
Requirements: each results record contains an identifier and two integer scores from 0 to 10 inclusive. Output each valid identifier, its total and Pass for totals of at least 12 or Retry otherwise. Invalid scores produce an Invalid record message. Write the valid results to a fresh report on each run; do not duplicate old results by appending to the previous report.
Represent rows and fields deliberately
A one-dimensional list represents a sequence. A two-dimensional structure can represent rows containing fields. For this project, each row has the fixed structure [identifier, score_one, score_two]. Python permits mixed types in a list, so the program must still respect the agreed field meaning.
records = [
["A17", 7, 5],
["B04", 3, 4],
["C21", 10, 10]
]
records[1] is the complete second row. records[1][2] is the third field in that row, the integer 4. Both indexes start at zero. Accessing records[3] would be out of range for these three rows. A table diagram with row and column indexes can prevent confusing a record number with a score-column number.
When traversing, choose either a row directly (for record in records) or indexes when you need their positions. Do not accidentally add an identifier string to a score. Two rows can have the same total without being the same record, so preserve the identifier when writing results.
Authentication is different from validation
Validation checks whether an input satisfies a rule, such as a score lying between 0 and 10. Authentication checks a claimed identity against credentials. A valid-looking username does not prove that the person entering it is the account holder.
This classroom example uses a tiny in-memory credential table to practise lookup. These are fictional teaching values. Real services should use an established authentication system with protected password handling; this plain-text table is not a production login design.
def authenticated(users, username, password):
for user in users:
if user[0] == username and user[1] == password:
return True
return False
Both credentials must match the same row. Finding the username in one row and the password in another must not authenticate the user. Test a correct pair, an incorrect password, an unknown username and a password belonging to a different row. Return false only after all candidate rows have been checked, not after the first non-match.
Separate calculation from input and output
A function should receive the values it needs and return a result the caller can use. This makes it possible to test a score calculation without reading files or asking someone to type. Local parameters prevent unrelated global values from silently controlling the result.
def classify(score_one, score_two):
total = score_one + score_two
if total >= 12:
return "Pass"
return "Retry"
def valid_score(score):
return score >= 0 and score <= 10
Here classify assumes scores have already been validated. State that precondition. Alternatively, design a function that validates and returns a structured result, but do not leave callers uncertain about which function owns the check. For totals 11 and 12, the expected classifications differ: those are important boundary tests.
Built-in and library subprograms can support a solution. len gives a sequence's length; int converts valid integer text; random.randint(1, 6) from Python's random module produces an integer from one through six inclusive. In a test, random output makes an exact expected value difficult to predict. Test properties such as the permitted range or use fixed inputs while debugging the surrounding logic. Do not invent a replacement for a supplied interface in an examination task.
Worked processing and file output
Start with the records above, which already contain integers. This version shows the processing separately from CSV conversion:
report = open("results_report.csv", "w")
for record in records:
identifier = record[0]
first = record[1]
second = record[2]
if valid_score(first) and valid_score(second):
total = first + second
outcome = classify(first, second)
report.write(identifier + "," + str(total) + "," + outcome + "\n")
else:
print("Invalid record:", identifier)
report.close()
Expected report lines are A17,12,Pass, B04,7,Retry and C21,20,Pass. Opening with "w" replaces the previous contents. Put that open operation before the loop; opening in write mode during every iteration would repeatedly erase earlier results. Closing finishes the program's use of the file and releases the resource.
For simple input CSV, agree that fields contain no embedded commas or quoted line breaks. Each line can be stripped of its line ending and split on commas. Check that it has three fields before indexing them. Convert the two score fields to integers, then check their ranges. Conversion and range validation are distinct steps. If malformed numeric text must be supported, handle it explicitly rather than assuming int() accepts every string.
Independent practice
Original project · 12 marks. Create scores.csv containing the three worked records, one row per line. Read it into a two-dimensional collection and produce the report. Extend it with D02,0,0, E08,6,5, F09,6,6 and G10,11,2. Record expected outcomes before running. Repeat the run to check that the report is not duplicated.
Project feedback and 12-mark scheme
Award: input file opened for reading [1]; rows split into three fields [1]; score fields converted to integers [1]; records retain identifier and both scores [1]; traversal processes all records [1]; both scores checked within 0–10 [2]; total calculated [1]; classification function called with the correct values [1]; valid output formatted as identifier,total,outcome [1]; invalid row excluded and identified [1]; report replaced on repeat runs and files closed [1].
Expected additional valid results are D02,0,Retry, E08,11,Retry and F09,12,Pass. G10 is invalid because 11 exceeds the single-score maximum. It must not be accepted just because its total is plausible. The second run should reproduce the same valid report, not add a second copy.
Complete file-processing model
This version accepts simple unquoted CSV records. It checks field count, identifier presence, ASCII numeric text and score range before writing. The authentication function earlier in the chapter is a separate classroom exercise: combine it with this processing only after testing the lookup independently.
def numeric_text(text):
if len(text) == 0:
return False
for character in text:
if character < "0" or character > "9":
return False
return True
def classify(first, second):
if first + second >= 12:
return "Pass"
return "Retry"
source = open("scores.csv", "r")
report = open("results_report.csv", "w")
for line in source:
fields = line.strip().split(",")
if len(fields) != 3:
print("Invalid record: expected three fields")
else:
identifier = fields[0].strip()
first_text = fields[1].strip()
second_text = fields[2].strip()
if identifier == "" or not numeric_text(first_text) or not numeric_text(second_text):
print("Invalid record:", identifier)
else:
first = int(first_text)
second = int(second_text)
if first > 10 or second > 10:
print("Invalid record:", identifier)
else:
total = first + second
outcome = classify(first, second)
report.write(identifier + "," + str(total) + "," + outcome + "\n")
source.close()
report.close()
Non-negative numeric text is established before conversion, so the later upper-bound checks complete the 0–10 rule. A negative sign is rejected as invalid numeric text for this score format. A missing input file still causes a runtime error: create the named file before running. Supporting inaccessible files or fully quoted CSV would require an explicitly extended design.
Exam practice and test evidence
A test record should contain the input, expected result, actual result and any change made. Include ordinary cases, each relevant boundary, invalid cases and empty input. An empty input file should produce an empty report without trying to calculate an average or access a missing first row.
If requirements add an average, handle a zero valid-record count before division. If they require first-match search, do not return a later duplicate without considering that requirement. Fitness for purpose means satisfying the full specification, not merely getting the demonstrated three rows right.
For a real Paper 2 attempt, use the supplied files and current examination instructions. Identify required filenames and interfaces before editing, save each answer where requested and test a small change before proceeding. The PMT Paper 2 archive provides source papers; official coding files must match the chosen paper. Do not submit this project's starter as though it were an official file.
Homework and reflection
Add a lookup by identifier. State whether identifiers are guaranteed unique; if not, specify whether the first or every matching row should be returned. Test a first-row match, last-row match and missing identifier. Then explain one use each of sequence, selection, iteration, a data structure and a returned value in your own solution.
Readiness checklist
You should be able to explain why both credentials must match one row; why scores need conversion and validation; why write mode belongs outside the loop; why the threshold tests include totals 11 and 12; and why an empty file is a distinct case. A functioning program plus a reasoned test record is stronger evidence than a screenshot of one successful run.
Sources and further practice
This chapter is written for Pearson Edexcel GCSE Computer Science 1CP2. Use the specification references in the chapter heading to locate the relevant requirements. Practice questions and point allocations on this page are original Proof Academy teaching material unless a question is explicitly identified as a sourced past-paper bridge.
- Pearson Edexcel 1CP2 specification
- PMT Paper 1 papers and mark schemes
- PMT Paper 2 papers and mark schemes
When using an original paper, open its matching mark scheme and supplied coding files where required. Use that paper's instructions and marks. A short classroom exercise is not a substitute for a full official task.
Keep your evidence
Export your notes before changing devices.
Notes stay in this browser. The Quiz tab records the chapter check, and Resources holds the long-answer questions.