Intermediate
Inheritance and polymorphism
Write a class Animal with __init__(self, name) and a method speak() that returns "...", and intro() that returns name + " says " + self.speak().
Write subclasses Dog (speak returns "Woof") and Cat (returns "Meow"). Do not repeat __init__ or intro in them.
Write a function chorus(animals) that returns a list of every animal's intro().
What Check tests
- A plain Animal says ...
- Dog and Cat override speak
- Dog and Cat are subclasses of Animal
- Subclasses reuse the parent's
__init__ chorusworks on a mixed list
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.