Lesson 6.2 · Trace it
Trace: find skipped value
Python code8 rows to fill4 marks
Complete the trace table for this Python code. This code is meant to add up every value in readings. The right total is 21. The code runs with no error message, but total ends up wrong. Then answer the question below the table. [4]
Line 1: readings = [6, 2, 9, 4]Line 2: total = 0Line 3: i = 1Line 4: while i < len(readings):Line 5, indented 1 level: total = total + readings[i]Line 6, indented 1 level: i = i + 1
Fill in one row each time a line changes i or total. 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.
| Row | i | total |
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 6 | ||
| 7 | ||
| 8 |