Skip to content
ExamSpine

Lesson 5.11 · Trace it

Trace: carry larger

Python code8 rows to fill3 marks

Complete the trace table for this Python code. range(1, len(nums)) starts i at 1, so the loop compares each value with the one before it. Then answer the question below the table. [3]

Line 1: nums = [5, 2, 6, 1, 4]
Line 2: for i in range(1, len(nums)):
Line 3, indented 1 level: if nums[i] < nums[i - 1]:
Line 4, indented 2 levels: nums[i] = nums[i - 1]

Fill in one row each time a line changes i or nums. 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.

Rowinums
1
2
3
4
5
6
7
8