Lesson 3.8 · Trace it
Trace: nested count
Python code10 rows to fill3 marks
Complete the trace table for this Python code. range(a, b) gives the whole numbers from a up to, but not including, b, and range(i) starts at 0. [3]
Line 1: count = 0Line 2: for i in range(1, 3):Line 3, indented 1 level: for j in range(i):Line 4, indented 2 levels: count = count + 1Line 5: print(count)
Fill in one row each time a line changes i, j or count, 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 | j | count | output |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 | ||||
| 7 | ||||
| 8 | ||||
| 9 | ||||
| 10 |