Community resourceWorksheet
1CP2-CT-4.3 Traversing two-dimensional lists
Part 3 of 7 · 1CP2-CT-4 · Structures, validation and search
The traversal worksheet, where the outer loop chooses the row and the inner loop chooses the field.
Students will:
- calculate how many times an inner-loop body executes
- trace a nested traversal that accumulates a total
- process one field from every record
- choose the smallest traversal a requirement actually needs
- explain the effect of resetting a total inside the row loop
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-4 · Structures, validation and search, part 3 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.
Traversing two-dimensional lists
To traverse a structure is to visit its items systematically. A two-dimensional structure normally needs a loop for its rows and another loop for the fields inside each row.
1. Outer and inner loops
The outer loop selects one row. The inner loop completes every field in that row. Only then does the outer loop move to the next row.
for row in table:
for value in row:
print(value)
- inner
- outer
- selection
- traversal
A rectangular structure has 4 rows and 3 fields per row. How many times does the inner-loop body execute during a full traversal?
- A3
- B4
- C7
- D12
2. Trace row-by-row accumulation
The algorithm adds every value. Record the changing row, value and total. Blank boxes mean unchanged.
Trace the nested traversal and complete the table.
Follow the inner loop across each row before moving to the next.
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.
numbers = [[2, 4], [3, 5]]total = 0for row in numbers:for value in row:total = total + valueprint(total)
| Row | numbers | total | row | value | Output |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 | |||||
| 6 |
Explain why the final total is 14 and how the nested loops produce it.
Refer to both loop roles and the four visited values.
Students type their answer here.
3. Process one field from every record
sales contains [product, units] records. Use a loop to add field 1 from every row into total_units. Print the total. You do not need an inner loop when only one known field is required.
sales = [["Pen", 12], ["Pad", 7], ["File", 9]]
# Add the units field from every row and print the total.
4. Choose the smallest suitable traversal
Use nested loops when every field must be processed. Use one row loop plus a fixed field index when only one field from each record is needed. Extra loops increase cognitive load and can accidentally process values that are irrelevant.
Compare the traversal needed to print every field with the traversal needed to total only field 2 from each record.
State the loop structure and indexing for each purpose.
Students type their answer here.
What is the effect of placing total = 0 inside the row loop when calculating a grand total?
- AIt makes every field a string.
- BIt resets the accumulator for each row, losing earlier rows.
- CIt creates an extra field.
- DIt automatically validates the values.
Route forward
You can traverse a rectangular structure and choose between full nested traversal and one-field row processing. Next you will stop unsuitable input before it enters such structures.