Lesson 8.1 · Trace it
Trace: two objects
Python code3 rows to fill3 marks
Complete the trace table for this Python code. Jar is a class. a and b are objects made from it, and sweets is an attribute that each of them keeps. Then answer the question below the table. [3]
Line 1: class Jar:Line 2, indented 1 level: passLine 3:Line 4: a = Jar()Line 5: a.sweets = 4Line 6: b = Jar()Line 7: b.sweets = 9Line 8: a.sweets = a.sweets + 3Line 9: b.sweets = b.sweets - a.sweetsLine 10: x = a.sweetsLine 11: a.sweets = 0Line 12: y = b.sweets + a.sweetsLine 13: print(x + y)
Fill in one row each time a line changes x or y, 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 | x | y | output |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 |