Lesson 2.9 · Trace it
Trace: two ifs
Python code5 rows to fill2 marks
Complete the trace table for this Python code. [2]
Line 1: age = 14Line 2: ticket = "child"Line 3: if age >= 12:Line 4, indented 1 level: ticket = "adult"Line 5: if ticket == "child":Line 6, indented 1 level: price = 5Line 7: else:Line 8, indented 1 level: price = 10Line 9: print(price)
Fill in one row each time a line changes age, ticket or price, 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 | age | ticket | price | output |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 |