Skip to content
ExamSpine

Lesson 3.4 · Trace it

Trace: sum loop

Python code9 rows to fill2 marks

Complete the trace table for this Python code. [2]

Line 1: total = 0
Line 2: n = 1
Line 3: while n <= 3:
Line 4, indented 1 level: total = total + n
Line 5, indented 1 level: n = n + 1
Line 6: print(total)

Fill in one row each time a line changes total or n, or prints something. The table already has the right number of rows. In each row, write only what that line changes; you can leave the other cells empty or copy their values down. Write values the way Python shows them: 3 and 3.0 are different, and text goes in quotes. In the output column, write exactly what appears on screen, with no quotes around it.

Rowtotalnoutput
1
2
3
4
5
6
7
8
9