CP1 practice paper: marking points and worked answers
Open this page only when you have finished the CP1 practice paper.
How to mark your paper
The paper has ten points of one mark each. A point is either earned or not; there are no half marks. For each point below you will find when it is earned, a worked answer, and the usual ways to miss it. The worked answer is one way to earn the point. Other wording that shows the same evidence earns it too. Mark what you wrote, not what you meant.
Each point stands on its own. A wrong place in Q2a does not cost Q2b if your trace still reaches the fault with values. A wrong repair in Q4a does not cost Q3a or Q3b; mark Q3c against your own repair. Handwriting, spelling, test names and comment style earn and cost nothing.
Add up your raw total out of 10. On the real paper, the recorded mark is raw × 0.75, so 7.5 at most.
Q1: the agent session (LO1)
Q1a (1 mark)
Earned when you name turn 5 and say that its claim that no file uses the old name has no evidence, citing turn 4: the search returned an error, so nothing was searched.
Worked answer. Turn 5. "No file in the project uses the old name any more" has no
evidence. The only search after the rename, in turn 4, returned error:. The tool table
says that this means the search did not run, so it is not the same as no matches. Turn 1
searched only for the definition, before the change. Turn 2 changed only receipts.py.
The test part of the claim is supported. Turn 3 ran test_receipts after the only change
(turn 2) and reported 6 passed, but only for that one test file. The missing evidence is
a search for donor_label after turn 2 that returned no matches, or a run of every test
file in the project.
Usual ways to miss it.
- Naming turn 4 as the claim. Turn 4 is the failed tool call. The claim is in turn 5.
- Calling the test claim unsupported. Turn 3 ran after the last change, so it supports that part.
- Reading
error:as "nothing found".
Q1b (1 mark)
Earned when you say the session ended because the reply in turn 5 had no tool call, and that the instruction is text the agent reads, which nothing in the controller checks.
Worked answer. The controller ends the session at the first reply without a tool call,
whatever that reply says. Turn 5 is such a reply, so the session stopped with final. The
agent had used 4 of the 10 allowed calls. The instruction to search is in the system prompt.
The agent even followed its wording, since turn 4 is a search. But nothing checks that the
search worked before the controller accepts a final reply. The controller only runs tool
calls and counts them. A prompt only asks. Only a check in a tool or in the controller would
enforce the instruction. For example, the controller could refuse a final reply until find
has returned no matches.
Usual ways to miss it.
- "It reached the limit of tool calls" (
tool_limit). It used 4 of 10 calls. - "The agent ignored the instruction", without saying why the instruction could not stop the claim.
Q2: locate and trace the fault (LO4)
Q2a (1 mark)
Earned when you name to_grams, line 15, and say that it returns amount, the number
as written, instead of grams, the weight converted on lines 12 to 14.
Worked answer. to_grams, line 15: it returns amount where it should return grams.
Line 14 computes the right weight for a kg entry, and line 15 throws it away. Naming
lines 12 to 15 also earns the point if you say that the converted value is never returned.
Usual ways to miss it.
total_grams, line 21. That line adds whateverto_gramsgives it. The wrong value is produced earlier.receipt_line, lines 31 and 32. Those lines work around the fault. They do not produce it.- "Line 14 is wrong." Line 14 computes the right value.
Q2b (1 mark)
Earned when your trace takes total_grams(["3 kg", "500 g"]) through to_grams and
split_weight with the values that matter, and reaches 503.
Worked answer.
| Step | Values |
|---|---|
total_grams starts |
total = 0 |
entry "3 kg": split_weight |
amount = 3, unit = "kg" |
to_grams lines 12 to 15 |
grams = 3, then grams = 3000 on line 14; line 15 returns amount, which is 3 |
back in total_grams |
total = 3 |
entry "500 g": split_weight |
amount = 500, unit = "g" |
to_grams lines 12 to 15 |
grams = 500; line 13 is false; line 15 returns 500 |
back in total_grams |
total = 503, which is returned; the rules give 3500 |
Usual ways to miss it. A trace with no values, or one that stops at total_grams
without reaching line 15.
Q2c (1 mark)
Earned when you say that every kg entry is wrong and every g entry is right, and why.
Worked answer. Every kg entry comes back as the number written, 1000 times too small.
The reason is that the converted value in grams is never returned. Every g entry is
right. For a g entry, line 14 does not run, so grams and amount hold the same number.
Returning either one gives the right weight. This also explains why the printed tests pass.
The only test with a kg entry goes through receipt_line, and receipt_line multiplies
by 1000 itself on lines 31 and 32.
Usual ways to miss it. Naming only the wrong inputs, such as "big weights" or "the report's entries", without the right ones and the reason.
Q3: a regression test (LO5)
Q3a (1 mark)
Earned when you write one assertion on a printed function whose input includes a kg
entry that the listing as printed gets wrong.
Worked answer. assert to_grams("3 kg") == 3000. These also earn the point:
assert total_grams(["3 kg", "500 g"]) == 3500 and
assert two_person_items(["5 kg"]) == ["5 kg"].
Usual ways to miss it.
- An input with only
gentries. The listing already gets it right, so the test passes before the repair. assert receipt_line("2 kg") == "2000 g": it passes on the printed listing too.assert to_grams("3 kg") == 3: the expected value is copied from what the code does now.
Q3b (1 mark)
Earned when your expected value is right and you take it from a printed rule.
Worked answer. The first rule (1 kg is 1000 g) and the second rule (to_grams returns
the weight in grams) together give the value: "3 kg" is 3000. The two_person_items
assertion also needs the third rule: 5000 g or more needs two people.
Usual ways to miss it. "From running the code", or a value with no source. Write the expected value from the rules before you look at the code.
Q3c (1 mark)
Earned when you state correctly what the printed listing returns for your input and what it returns after your own repair.
Worked answer. As printed, to_grams("3 kg") returns 3. After the repair in Q4a it
returns 3000. For the other two assertions: total_grams(["3 kg", "500 g"]) returns 503,
then 3500; two_person_items(["5 kg"]) returns [], then ["5 kg"].
Usual ways to miss it. Giving the expected value as the "before" result, or not working the "after" result through your own repair.
Q4: the repair and its callers (LO4)
Q4a (1 mark)
Earned when your change is in to_grams and makes it return the weight in grams for
every entry.
Worked answer. Line 15 becomes return grams. Rewriting lines 12 to 15 so that a
kg entry returns amount * KG and a g entry returns amount also earns the point.
Usual ways to miss it.
- Changing
total_gramsor another caller. Thento_gramsstays wrong for everything else that calls it. return amount * KGon line 15: everygentry becomes 1000 times too big.- A special case for
"3 kg", which hides the report and leaves every otherkgentry wrong.
Q4b (1 mark)
Earned when you address all three callers, and you name receipt_line as the one that
must change, with lines 31 and 32 and one input.
Worked answer.
| Caller | Right after the repair? | Must its own lines change? |
|---|---|---|
total_grams |
Yes: total_grams(["3 kg", "500 g"]) gives 3500 |
No |
two_person_items |
Yes: two_person_items(["5 kg"]) gives ["5 kg"] |
No |
receipt_line |
No: receipt_line("2 kg") gives "2000000 g", and the printed test that expects "2000 g" fails |
Yes: delete lines 31 and 32, which multiply a kg weight by 1000 a second time; it then gives "2000 g" |
The comment on line 32 is the clue. Someone corrected the symptom in one caller instead of
the fault in to_grams. So that correction has to go when the fault is repaired.
Usual ways to miss it. Leaving out a caller, or saying receipt_line is fine because
its test passes today.
Check your answers by running the listing
The paper is sat without running anything. Afterwards, running the listing shows whether
your reasoning held. The block below is the listing without its line numbers, so line 15 of
the file is line 15 of the paper. After the listing come the four printed tests and the
report's call.
Save it as cp1_practice.py in a scratch folder of your own, outside the course checkout.
KG = 1000 # grams in one kilogram
HEAVY = 5000 # grams: an item this heavy or heavier needs two people
def split_weight(entry):
"""Split an entry such as "750 g" into (750, "g")."""
amount, unit = entry.split()
return int(amount), unit
def to_grams(entry):
"""The weight of one donated item, in grams."""
amount, unit = split_weight(entry)
grams = amount
if unit == "kg":
grams = amount * KG
return amount
def total_grams(entries):
"""The weight of all the items together, in grams."""
total = 0
for entry in entries:
total += to_grams(entry)
return total
def two_person_items(entries):
"""The items that need two people to lift."""
return [entry for entry in entries if to_grams(entry) >= HEAVY]
def receipt_line(entry):
"""The weight printed on the donor's receipt."""
grams = to_grams(entry)
if entry.endswith("kg"):
grams = grams * KG # added in April: receipts showed kg items too light
return f"{grams} g"
# The four tests printed on the paper.
assert to_grams("750 g") == 750
assert total_grams(["200 g", "450 g"]) == 650
assert two_person_items(["6000 g", "900 g"]) == ["6000 g"]
assert receipt_line("2 kg") == "2000 g"
print("printed tests: pass")
# The report's call.
print("report:", total_grams(["3 kg", "500 g"]))
Run it in that folder with the course's Python environment active:
python cp1_practice.py
printed tests: pass
report: 503
Now add your Q3 assertion as the last line of the file and run it again. With the worked
answer's assert to_grams("3 kg") == 3000, the same two lines print. Then the run ends
with AssertionError. The test fails before the repair, as a regression test must.
Then make your Q4a repair and run again. With line 15 changed to return grams, the run
stops at once with AssertionError on the printed test
assert receipt_line("2 kg") == "2000 g", before anything prints. That failure is the
caller from Q4b. Delete lines 31 and 32 and run once more:
printed tests: pass
report: 3500
Your Q3 assertion now passes too. The course ran these three versions with Python 3.12 on 15 October 2026. The output above is what they printed.