Skip to content
Snippets Groups Projects
Select Git revision
  • 5cb489fc81ce13abec9dc1cae85e0890b101ecfa
  • master default
2 results

for_loop_summation.c

Blame
  • barnyard.py 1008 B
    class Animal:
        """
        This 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.')