Skip to content
ExamSpine

Lesson 2.9 · Trace it

Trace: elif update

Python code3 rows to fill3 marks

Complete the trace table for this Python code. Then answer the question below the table. [3]

Line 1: temp = 18
Line 2: if temp < 10:
Line 3, indented 1 level: temp = temp + 5
Line 4: elif temp < 20:
Line 5, indented 1 level: temp = temp + 3
Line 6: elif temp < 30:
Line 7, indented 1 level: temp = temp - 2
Line 8: print(temp)

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

Rowtempoutput
1
2
3