barnyard.py 1011 Bytes
Newer Older
Christopher Bohn's avatar
Christopher Bohn committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Animal:
    """
    This is base class should not be directly instantiated. All subclasses should have a move() method.
    """
    def __init__(self, name):
        self.name = name

    def make_sound(self):
        print(f'{self.name} is staying quiet.')


class Fish(Animal):
    def move(self):
        print(f'{self.name} is swimming.')


class Footed(Animal):
    def move(self):
        print(f'{self.name} is walking.')

    def make_sound(self):
        print('Moo. Bark bark. Meow.')


class Fowl(Animal):
    def walk(self):
        print(f'\t{self.name} is walking.')

    def fly(self):
        print(f'\t{self.name} is flying.')

    def move(self):
        choice = input(f'Should {self.name} move with feet or wings? ')
        if choice.lower()[0] == 'f':
            self.walk()
        elif choice.lower()[0] == 'w':
            self.fly()
        else:
            print(f'\t{self.name} doesn\'t know how to move using {choice}.')

    def make_sound(self):
        print('Bok bok.')