Lesson 5.6 · Trace it
Trace: list changes
Python code4 rows to fill4 marks
Complete the trace table for this Python code. append adds a value at the end. pop(1) removes the value at index 1 and gives it back. [4]
Line 1: nums = [5, 3, 8]Line 2: nums[0] = 6Line 3: nums.append(4)Line 4: x = nums.pop(1)Line 5: y = nums[1]Line 6: n = len(nums)Line 7: print(x + y + n)
Fill in one row each time a line changes x, y 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.
| Row | x | y | n | output |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 |