

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


The following block of code is used in each part of the exercise. It is repeated for readability.
1 | class Dog: 2 | def init(self, name = "", owner = None): 3 | self.name = name 4 | self.owner = owner 5 | def speak(self): 6 | print("WOOF!") 7 | 8 | class Owner: 9 | def init(self, name): 10 | self.name = name 11 | def speak(self): 12 | print("My name is:", name)
###########. OPTION 1 fido = Dog()
###########. OPTION 2
fido = Dog ("Fido")
###########. OPTION 3
fido = Dog (name = "Fido")
new_owner = Owner("David") fido = Dog("fido", new_owner)
###########. OPTION 2
fido = Dog(name = "Fido", owner = Owner("David"))
new_owner = Owner() # Owner has no name variable fido = DOg(new_owner)
new_owner = Owner() # Owner has no name variable fido = Dog(owner = new_owner)