Lesson 5.5 · Trace it
Trace: list index
Python code5 rows to fill4 marks
Complete the trace table for this Python code. prices[i] is the value at index i, and len(prices) is the number of values. [4]
Line 1: prices = [4, 9, 2, 7]Line 2: i = 1Line 3: a = prices[i]Line 4: i = len(prices) - 1Line 5: b = prices[i]Line 6: print(a + b)
Fill in one row each time a line changes i, a or b, 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 | i | a | b | output |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 |