Catalog

≈ 55 min · Grade 9 · Computer Science

Tracing Accumulators in Loops

Use it as it is, or make it yours.

Print it and teach it today. Or make it yours in VeraTeach and say how you want to teach it — the timings, the examples, the activity, who needs more support.

Make this mine

Free to read, print, copy and use in your own classroom. Not for republishing or resale — terms.

Checked by VeraTeach before publishing · September 2026

Teacher asked for
accumulators in loops
Teacher's note
“They can read a loop but they cannot say what the variable holds partway through. First programming course.”
Objective produced
Write and trace a loop that accumulates a running total, identifying what the accumulator holds after each pass.

Materials & Prep

  • Projector or board.
  • Students need access to a Python editor or classroom coding platform.
  • Prepare the displayed code and a trace table with columns: pass, current value, accumulator before, value added, accumulator after. Post the scoreboard values 3, 1, and 4 for the opening.
0–7min

Opening prediction

DisplayA scoreboard begins at 0. A team earns 3 points in round 1, 1 point in round 2, and 4 points in round 3. Ask students to write the scoreboard total after each round, without using code: after round 1, after round 2, and after round 3.

Turn and talkStudents compare their three totals and explain what information they carried from one round to the next. Expected responses are 3, 4, and 8.

ConnectStudents just kept a running total. In a program, a variable can hold that changing total. The variable that stores the total as the loop repeats is called an accumulator. Today, students will write the loop and identify exactly what the accumulator holds after every pass.

7–17min

Model the running total

AnalogyTreat the accumulator like a scoreboard. It holds the score so far, and each loop pass adds the next value to that same score.

Think aloudStart with running_total equal to 0. On the first pass, points is 4, so I calculate 0 + 4 and store 4 back in running_total. On the second pass, points is 7. I do not start over at 0; I use the current value, 4, and calculate 4 + 7, which stores 11. On the third pass, I calculate 11 + 2 and store 13. The common error is tracing each pass from the initial 0 instead of carrying the updated accumulator forward.

Display the completed trace

passpointsaccumulator beforecalculationaccumulator after
1400 + 44
2744 + 711
321111 + 213

ExpectedThe loop prints 4, then 11, then 13. After the second pass, running_total holds 11, and after the loop it holds 13. Point back to the scoreboard: running_total holds the score so far, exactly as students carried the total from one round to the next.

17–25min

Guided trace and check

Have students complete the trace for this code without running it:

total = 0

for value in [6, 3, 5]

total = total + value print(total)

ScaffoldProvide the sentence frame, “Before this pass, total is . Add to get . After this pass, total holds .” Students may fill in the displayed table rather than write full sentences.

Check for understandingAsk students to hold up or submit the accumulator value after pass 1, pass 2, and pass 3. Expected answers are 6, 9, and 14. Ask one student to justify the second answer by naming the value carried from pass 1. Listen for students who answer 3 or 5 because they are naming the current list item instead of the accumulated total.

25–32min

Debug the misconception

Confront: Display this incorrect revision

total = 0

for value in [6, 3, 5]

total = value print(total)

Ask students to predict its output before discussion. It prints 6, 3, and 5 because each pass replaces total rather than adding to the value already stored. Compare the two assignment statements: total = value discards the previous total, while total = total + value uses it. Students annotate the exact line that causes the running total to be lost.

Turn and talkExplain why the incorrect code does not produce 14 after the final pass. Expected: the final assignment stores 5, so the earlier values are not retained.

32–47min

Build and test an artifact

Students write and run this small program, then add a trace comment or table beside it:

values = [8, 3, 5] total = 0

for value in values

total = total + value print("After pass:", total)

print("Final total:", total)

Have students trace before running. Expected numeric accumulator values are 8 after pass 1, 11 after pass 2, and 16 after pass 3; the final total is 16. Students then change the list to [8, 3, 5, 0], predict the additional pass, and run the program. The accumulator remains 16 after the fourth pass because 16 + 0 equals 16.

CirculateRequire students to point to the accumulator’s value before and after each pass. If a student is stuck, cover the later list items and complete the first row with the student using the frame, “old total + current value = new total.”

ExtensionTest an empty list by changing values to []. Predict the final total before running. With no loop passes, the final total is 0. Students ready for more may modify the program to print only the final total while preserving the same accumulation logic.

47–55min

Exit check

Exit ticketWithout running code, write a loop that starts an accumulator at 0, adds each value in [2, 6, 3], and prints the accumulator after each pass. Under the code, state what the accumulator holds after pass 1, pass 2, and pass 3, and explain in one sentence why the second value is not the accumulator after pass 2.

ExpectedThe accumulator holds 2 after pass 1, 8 after pass 2, and 11 after pass 3. A complete explanation says that pass 2 carries forward 2 and adds 6, so the accumulator becomes 8. Collect the code and trace as the closing evidence of the objective.

Not quite right for your class?

Tell VeraTeach what you’d change — in your own words, the way you’d say it to a colleague.

Free · nothing is changed yet

Change it to fit your class, in your own words.

Make this mine