<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">"""
Module containing a superclass Animal, with
subclasses Bird, Parrot, and Penguin.

Author: Bracy (awb93), Lee (ljl2), and Fan (kdf4)
Date:   April 2020
"""

class Animal():
    """
    An instance is a single animal with a name, id number, and weight.
    """
    # Class Attribute
    n_animals = 0
    CAN_SWIM = False
    CAN_FLY = False
    CAN_SPEAK = False

    # BUILT-IN METHODS
    def __init__(self, name, weight=50):
        """
        Creates a new Animal with a unique tag number.
        name: name of animal [str]
        tag_no: unique identifier for each instance [int]
        weight: weight of the animal [int]
        """
        # Instance attributes
        assert type(name) == str
        self.name = name
        self.tag_no = Animal.n_animals
        self.weight = weight
        Animal.n_animals += 1

    def speak(self, words):
        """
        prints out the words to the screen if the animal can talk
        """
        if self.CAN_SPEAK:
             print(words)

    def eat(self):
        """
        Prints out eating sound &amp; animal gains small amount of weight.
        """
        print("NOM NOM NOM")
        self.weight += 1

    def __str__(self):
        action= ''
        if self.CAN_SWIM:
            action += 'It swims! '
        if self.CAN_FLY:
            action += 'It flies! '
        if self.CAN_SPEAK:
            action += 'It speaks! '
        return "tag "+str(self.tag_no)+": "+self.name+" is a "+ \
            str(self.weight)+" pound "+type(self).__name__+". "+action


class Fish(Animal):
    """
    An instance is a fish.
    """

    CAN_SWIM = True   # override the Animal default

    def __init__(self, name, weight=3):
        """
        superclass assigns all attributes, but weight defaults to 3
        """
        super().__init__(name, weight)

    def eat(self):
        """
        Prints out eating sound &amp; animal gains small amount of weight.
        """
        print(". . .")
        self.weight += 1

class Bird(Animal):
    """
    An instance is a bird.
    """

    CAN_FLY = True

    def __init__(self, name, weight=2):
        """
        superclass assigns all attributes, but weight defaults to 2
        """
        super().__init__(name, weight)

    def eat(self):
        """
        Prints out eating sound &amp; animal gains small amount of weight.
        """
        print("Peck Peck Peck!")
        self.weight += 1

class Parrot(Bird):
    """
    An instance is a parrot.
    """

    CAN_SPEAK = True  # override the Bird default

    def speak(self, words):
        """
        prints out the words to the screen and asks for a cracker
        """
        super().speak(words)
        print("Now give me a cracker!")


class Penguin(Bird):
    """
    An instance is a penguin.
    """
    CAN_FLY = False  # override the Bird default
    CAN_SWIM = True  # override the Animal default

    def __init__(self, name, weight=25):
        """
        superclass assigns all attributes, but weight defaults to 25
        """
        super().__init__(name, weight)
</pre></body></html>