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 | |
|---|---|---|
| 1pets.append(Pet("Rex")) | AThe method is called without an object and is not indented inside the loop. It should be indented and written as p.speak(). | |
| 2for p in pets: p.speak() | Bpets = [] | |
| 3Create an empty list ready to store many objects | CThe closing bracket for append() is missing, so there is a syntax error. It needs two closing brackets at the end. | |
| 4Find an object in the list by checking one of its attributes | Dif p.name == "Rex": | |
| 5pets.append(Pet("Rex") | ECreates a new Pet object and adds it to the end of the pets list | |
| 6for p in pets: speak() | FLoops over every object in the pets list and calls its speak() method |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
objects.append(obj) — Adds an object to the end of a list so many objects are stored together. You can then loop over the list with a for loop to call each object's methods or find one by its attribute.students = []
students.append(Student("Ava", 7))for s in students:
s.show()for pet in pets:
pet.speak()for s in students:
if s.name == "Ava":
print(s.points)students = []
students.append(Student("Liam", 8))
print(len(students))