Animal Sounds
Python
30 pts
Animal Sounds
Create an abstract class Animal:
__init__(self, name)stores the name.- An abstract method
sound(self). - A normal method
speak(self)that returnsname says sound, usingself.sound().
Then create two child classes, Dog (its sound() returns "Woof") and Cat (returns "Meow"). Do not write speak() or __init__ in the child classes — they get them from Animal.
Expected output:
Bobby says Woof Mimi says Meow
Checklist
- Define an abstract class
Animalwhose__init__stores the name and which has an abstract methodsound(self). - Add a normal method
speak(self)toAnimalthat returnsname says soundusingself.sound(). - Create the child classes
DogandCat, each with only its ownsound(). - Run the code at the bottom.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
