A loop that ends holding an answer
Both loops so far printed something on each pass and then forgot it. Nothing survived. Ask them for the class total afterwards and there is nothing to ask.
This one carries a number forward. Each pass takes what the box is already holding, adds one more mark, and puts it back — so when the loop ends, the box holds the whole total.
total = total + mark.A counter is the same idea with a fixed step:
count = count + 1, which adds one for every pass regardless of what the pass contained.Read either line right-hand side first, as you did in problem 2: work out the new value, then put it back in the same box.
total = total + mark reads the box before it writes to it. On the very first pass there has to be something in there already, so the box is created and set to nought above the loop.Starting it at anything other than nought quietly adds that much to your answer. Starting it inside the loop would reset it on every pass, and the total would end up holding nothing but the last mark.
Why sum() is not the point here
You already know sum(marks) from problem 7, and it is the right thing to use in real work. The pattern matters anyway, because most of what you will want to accumulate has no ready-made function: a running total of only the students who passed, a count of the missing entries, a tally per city. Every one of those is this same three-part shape — set a box to nought, add to it inside the loop, use it after.
What you are building
Build the programme
Four things have to happen, and the marks are already in place. Click them in an order that works.
Two questions settle it. What must exist before the loop can add to it? And what cannot be worked out until the loop has finished?
Your plan
The steps still to place
Your programme written out in full. Five pieces are missing. Three of them produce a number that is wrong by a believable amount, which is worse than a number that is obviously wrong.
Leave nothing on "choose…". A wrong pick does not always cause an error — sometimes it just prints something you did not expect, which is the harder kind of mistake to spot.
Run and read
Here is the whole programme. The marks are yours to change. Check the count against the number of marks you typed — that is the quickest way to catch a loop that is not doing what you think.