Read the program before writing another one
A proposed Python pizza lesson using PRIMM: predict, trace and repair a loop, then calculate a price independently. Typing along isn't enough.

In this post
I want beginners to read and explain a short program before I ask them to write another one. Getting everyone’s screen to match mine is a fine test of my dictation, but a rubbish test of their understanding.
Here’s a Python lesson you can use to check the difference. It follows PRIMM: Predict, Run, Investigate, Modify, Make. We’ll stay with one pizza order, first understanding its description, then independently calculating its price. It’s for learners who have met lists, loops, assignments and strings, but are still learning how to put them together.
Predict before pressing Run
Give learners this file rather than making them earn their pizza by copying punctuation:
toppings = ['mushrooms', 'olives']
description = 'Cheese with '
for topping in toppings:
description = description + topping + ' and '
print(description)The pizza setting comes from Sue Sentance, Jane Waite and Maria Kallia’s PRIMM paper. The programs, prices and tasks here are my own proposed adaptation.
Before you run anything, ask each learner to write down the exact line they think will appear, followed by a short reason. Do this individually first. Otherwise, we risk collecting one person’s understanding and everybody else’s agreement.
Then we can:
- Compare predictions with a partner, discussing any differences in reasoning.
- Run the supplied file.
- Compare the result with the original prediction.
For your answer check, the expected output is 'Cheese with mushrooms and olives and \n'. That’s escaped notation: \n represents the newline that print() adds. There is also a space after the final and, because printing doesn’t remove the space already in the string.
Keep the original prediction. If someone expected a neatly finished description, you can ask which line now explains the difference. Crossing out the prediction and replacing it with the right answer would leave us with a tidy page and rather less information.
A correct prediction needs an explanation too. Spotting that the description looks unfinished isn’t quite the same as following how we built it.
Follow the description through the loop
Before repairing anything, let’s trace description. Ask learners to fill in this table, then you can compare their version with our answer. The quotation marks make the trailing spaces visible:
| Point in the program | Value of description |
|---|---|
| Before the loop | 'Cheese with ' |
| After the mushrooms | 'Cheese with mushrooms and ' |
| After the olives | 'Cheese with mushrooms and olives and ' |
The assignment inside the loop adds a topping and ' and '. It does that for every item, including the last one. The final and comes from that assignment, not from print().
On the right-hand side of description = description + topping + ' and ', description means the value we already have. We build a new string from it, then assign that result back to the same name. The next iteration starts with the updated value.
Now we’ve got a reason to introduce accumulator: a variable holding the result built so far. In our program, that result is text.
You can use these three questions to check the explanation:
- Why does the loop body run twice?
- Which statement creates the unwanted ending?
- What remains in
descriptioniftoppingsis empty?
With no toppings, the body runs zero times. Nothing changes the starting string, so we get 'Cheese with '. Our grammatical ambitions have exceeded our ingredients.
I’d want an explanation in ordinary words. Naming the keywords tells you someone recognises the syntax; explaining how the second row becomes the third tells you they’ve followed the update. Looking only at the printed line hides that distinction.
PRIMM has research behind it: Sentance, Waite and Kallia reported higher post-test results for the PRIMM group in a non-randomised school study involving pupils aged 11 to 14. Using the approach for this activity, including with adult beginners, is my proposed teaching choice. The study’s findings concern those school pupils.
Fix the description
Now you can give learners the behaviour we want: no final and, a sensible description with one topping, and simply Cheese with none. Ask them to work on the repair before showing the answer.
For our heroic effort to make lunch grammatical, this complete version uses a separator that changes after the first topping:
toppings = ['mushrooms', 'olives']
description = 'Cheese'
separator = ' with '
for topping in toppings:
description = description + separator + topping
separator = ' and '
print(description)We now get Cheese with mushrooms and olives, without anything hanging off the end. With one topping we get Cheese with mushrooms; with none, we keep Cheese.
The difference is that we put a separator before each topping. The first addition uses ' with '. Only afterwards does separator = ' and ' change what we’ll use next time.
That order matters. Ask learners to point at the assignment that changes the separator and explain why the first topping still gets with. If there isn’t another topping, the changed separator is never used.
These are the checks I’d use; you only need to change toppings. Keep the answer column to yourself until learners have predicted each run and explained their prediction:
toppings |
Expected description |
|---|---|
[] |
'Cheese' |
['mushrooms'] |
'Cheese with mushrooms' |
['mushrooms', 'olives'] |
'Cheese with mushrooms and olives' |
Each case checks something different. No toppings means neither assignment in the loop happens. One topping checks the initial separator. Two toppings check that we understand the change between iterations.
Of course, an experienced Python reader will want to use join(), and for ordinary application code I’d choose that too:
toppings = ['mushrooms', 'olives']
description = 'Cheese'
if toppings:
description = description + ' with ' + ' and '.join(toppings)
print(description)Here, join() puts ' and ' between the topping names, which are strings. The if toppings prevents us adding ' with ' to an order with no toppings.
I’d show this as the shorter formatting alternative, not another prerequisite for finishing the lesson. We’re keeping the explicit loop to make the changing values visible. There needn’t be a minimum code length for ordering a pizza.
Calculate the price independently
When you move on to pricing, put the formatting solution out of view. We’re keeping the same order, but giving learners a fresh job rather than another version to copy.
Give them only this specification:
- The base price is 600 pence.
extra_pricesholds the topping prices, starting with[80, 120].- Add every topping price to the base price.
- Print the total in pence.
The prices are invented for the exercise, which saves us debating what an olive ought to cost. Using integer pence also keeps the task about loops and changing values.
Ask learners to write the program independently, with ordinary syntax references allowed. You want them to decide where the starting value belongs and what changes for each topping. Remembering the position of a colon isn’t the point.
Keep this instructor reference until they’ve attempted the task:
extra_prices = [80, 120]
total_pence = 600
for price in extra_prices:
total_pence = total_pence + price
print(total_pence)Our total starts at 600, becomes 680, then 800. We’ve changed the job from assembling text to calculating a price, whilst keeping the idea of updating a result for each item.
Ask why total_pence = 600 belongs outside the loop. Setting it again for each topping would discard the earlier additions. Then ask why an empty list still gives 600: the starting assignment happens, whilst the loop body doesn’t.
Finally, add another topping price by changing the list to [80, 120, 50]. Ask for a prediction and explanation before running it; the expected total is 850. With only [80], it’s 680.
Judge the explanation and the cases, not resemblance to my reference answer. Requiring independent work and then rewarding imitation would rather undo the exercise.
When I’d call the exercise complete
For beginners who know the individual bits of syntax but struggle to combine them, I’d choose this over another copy-along demonstration. We get to see where their reasoning changes, rather than admiring a room full of matching screens.
I’d retain four small pieces of work:
- The original prediction and its reason.
- The trace through the description loop.
- The repair, explaining the zero-, one- and two-topping cases.
- The independent price calculation, explaining its starting value and updates.
You can use these to choose the next teaching step. If someone needs help following an update, work through another small trace with them. They need a smaller step, not an audience.
My verdict is that this is worth doing when we’re teaching loops and changing values. The pizza exercise is complete when the learner can explain the description and independently reuse the idea to calculate the price, not when their screen matches mine.
I’d prefer my actual cooking to remain unassessed.

