Skip to content
ExamSpine

Lesson 5.7 · Trace it

Trace: double loop

Python code9 rows to fill4 marks

Complete the trace table for this Python code. for x in nums gives x each value of nums in turn. [4]

Line 1: nums = [4, 1, 3]
Line 2: for x in nums:
Line 3, indented 1 level: x = x * 10
Line 4: first = nums[0]
Line 5: for i in range(len(nums)):
Line 6, indented 1 level: nums[i] = nums[i] + 1
Line 7: last = nums[2]
Line 8: print(first + last)

Fill in one row each time a line changes x, first or last, 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.

Rowxfirstlastoutput
1
2
3
4
5
6
7
8
9