Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1assert account.balance == 150 | AChecks that the balance attribute equals 150 after a method has run, and raises an AssertionError if it does not | |
| 2assert dog.speak() == "Woof" | Bdef test_deposit(): acc = Account(100) acc.deposit(50) assert acc.balance == 150 | |
| 3Test a setter with invalid input: call it with a bad value, then assert the attribute did not change | Cplayer.set_age(-5) assert player.age == 14 | |
| 4Write one test per method: create an object, call that method, then assert on the result | DA single = assigns a value and is a syntax error in an assert. Use == to compare the returned value with the expected one. | |
| 5assert car.drive(10) = 10 | EThe method call car.accelerate() is missing, so the speed never changes and the assert fails. Call the method before checking the attribute. | |
| 6car.speed == 20 assert car.speed == 20 | FCalls the speak() method and checks that the value it returns is exactly "Woof" |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
assert obj.method() == expected — Creates an object, calls its method, then uses assert to check the result or attribute equals what you expect. If it is False, Python raises an AssertionError.acc = Account(50)
acc.deposit(20)
assert acc.balance == 70acc = Account(50)
acc.deposit(20)
assert acc.balance == 70acc = Account(50)
acc.withdraw(20)
assert acc.balance == 30acc = Account(50)
acc.set_balance(-10)
assert acc.balance == 50acc = Account(50)
acc.deposit(20)
assert acc.balance == 70