Community resourceWorksheet

1CP2-CT-3.4 Iterating through a list

Part 4 of 7 · 1CP2-CT-3 · Lists, iteration and subprograms

The list iteration worksheet, visiting items one at a time and tracing the state that changes as the loop runs.

Students will:

  • say how many times a loop over a list repeats
  • complete a trace table for a loop that accumulates a value
  • explain why accumulated outputs differ from the raw items
  • process only the items that meet a condition
  • compare iterating by item with iterating by index

Inside: 6 explanation cells, 2 multiple-choice questions, 1 Python task, 1 trace table, 1 fill-in-the-blanks cell and 2 written answers. 14 marks, about 45 minutes.

Series: 1CP2-CT-3 · Lists, iteration and subprograms, part 4 of 7.

Shared by Coding PathwayVerified teacher

  • 13 cells
  • About 45 minutes
  • CC BY-SA 4.0
  • Shared 17 Aug 2026

Preview

The whole resource, exactly as a class sees it. Answers and marking are held back.

Iterating through a list

Iteration over a data structure means processing every item in turn. A direct for loop is usually safer and clearer than writing separate statements for every index.

This worksheet moves from reading the pattern to tracing a running total and then writing a loop that works for lists of different lengths.

1. One item at a time

scores = [4, 7, 5]
for score in scores:
    print(score)

On each pass, score receives the next item. The loop runs three times because the list has three items. No index is needed when the item value itself is what the program must process.

An index loop such as for index in range(len(scores)) is useful only when the position is also needed.

Fill in the blanks3 marks
In for score in scores, scores is the gap 1, score is the gap 2 that receives one item per pass, and the loop stops after the gap 3 item.
  • first
  • last
  • list
  • loop variable
  • output
Multiple choice1 mark

How many times does for colour in ["red", "blue", "green", "gold"]: repeat its indented body?

  • A3
  • B4
  • C5
  • DUntil a condition becomes false

2. Trace changing state

A trace table records values after each loop pass. For a running total, first write the initial value, then update it once for each item. The output column changes only when print() executes.

Complete the table for the short algorithm. Work through the values 2, 5 and 1 in order.

Trace table4 marks

Complete the trace table for this list iteration.

On each pass, copy the next value into `number`, update `total`, then record the printed total.

Use one row for each pass through the loop. Fill in a box only when that value changes on that row, and leave the rest blank.

ProgramPython
  1. total = 0
  2. for number in [2, 5, 1]:
  3. total = total + number
  4. print(total)
Trace table with 3 columns
RowtotalnumberOutput
1
2
3
4
5
6
Written answer2 marks

Explain why the outputs are cumulative rather than simply 2, 5, 1.

Describe the role and position of the accumulator.

Students type their answer here.

3. Process selected items

The list readings contains positive and negative temperature changes. Use a direct for loop to count how many readings are below zero. Store the result in below_zero and print only the final count.

Initialise the count before the loop. Test each item inside the loop. Increment only when the condition is true.

Coding task4 marks
readings = [3, -2, 0, -5, 4, -1]
# Count and print how many readings are below zero.

4. Generalise to changing data

Code that refers to each item by name, such as print(scores[0]), print(scores[1]), breaks when the list length changes. Direct iteration expresses the general rule: process whatever items are present.

Written answer3 marks

Compare a direct loop for item in values with for index in range(len(values)). Give one situation where each form is appropriate.

Decide whether the item value alone is enough or whether its position is required.

Students type their answer here.

Multiple choice1 mark

What is the likely result of using range(len(items) + 1) to visit every valid list index?

  • AThe final access is out of range.
  • BThe first item is skipped.
  • CThe list gains an item.
  • DThe loop runs one time fewer.

Route forward

You can process every list item and trace changing state. Next you will package a named action as a procedure and pass data into it using parameters.