Skip to content
ExamSpine

Lesson 7.5 · Trace it

Trace: linear search

Python code6 rows to fill4 marks

Complete the trace table for this Python code. The loop stops once found is True, or once no values are left. Then answer the question below the table. [4]

Line 1: values = [6, 2, 9, 4]
Line 2: target = 9
Line 3: i = 0
Line 4: found = False
Line 5: while i < len(values) and not found:
Line 6, indented 1 level: if values[i] == target:
Line 7, indented 2 levels: found = True
Line 8, indented 1 level: else:
Line 9, indented 2 levels: i = i + 1
Line 10: print(i)

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

Rowifoundoutput
1
2
3
4
5
6

Report a problem with this page