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 = [] | ACreates an empty list that will hold the program's objects, such as Pet objects | |
| 2def show_all(pets): | Bmain is written without brackets, so the function is never called and the program does nothing. It should be main(). | |
| 3main() runs a menu loop that keeps asking the user what to do until they choose to quit | Cpets.append(Pet("Rex", 3)) | |
| 4A class describes one kind of thing, and each object made from it is stored in the list | DA small function that receives the list of objects so it can handle them, for example printing each one | |
| 5def add_pet(name, age): pets.append(Pet(name, age)) return pets.append | Ewhile choice != "q": | |
| 6main print("Program finished") | FThe function ends with a broken return that does not give back anything useful. Each small function should do one clear job, so this one should just add the pet and need no return. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
modular program — A program split into parts: a class for its things, a list of objects, and small functions called from main(), planned with diagrams and checked with tests.class Song:
def __init__(self, title):
self.title = titlesongs = []
songs.append(Song("Hello"))def show(songs):
for song in songs:
print(song)def main():
while True:
choice = input("Choice: ")songs = []
songs.append(Song("Hello"))
assert len(songs) == 1