Command Palette

Search for a command to run...

Hectal
Phase 8: Object-Oriented Python
Python · Exercise 5 of 6 PreviousNext
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

  1. A plain Animal says ...
  2. Dog and Cat override speak
  3. Dog and Cat are subclasses of Animal
  4. Subclasses reuse the parent's __init__
  5. chorus works 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.