Solution 1

class Animal(object):
    pass


class Cat(Animal):
    def talk(self):
        return "Meow!"


class Dog(Animal):
    def talk(self):
        return "Ruff!"


class Human(Animal):
    def talk(self):
        return "Hello!"

Friendly Animals

Extend the Animal class provided with three more subclasses: Cat, Dog, Human.

Include a method talk in each one of the subclasses. The talk method should return different options based on the type of animal:

  • Cat: should return "Meow!"
  • Dog: should return "Ruff!"
  • Human: should return "Hello!"

Test Cases

test animals talking - Run Test

def test_animals_talking():
    cat = Cat()
    dog = Dog()
    human = Human()

    assert isinstance(cat, Animal)
    assert isinstance(dog, Animal)
    assert isinstance(human, Animal)

    assert cat.talk() == 'Meow!'
    assert dog.talk() == 'Ruff!'
    assert human.talk() == 'Hello!'
class Animal(object): pass