<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">from zoology import Animal, Fish, Parrot, Bird, Penguin
"""
A module that supports creating and admitting animals to the zoo.
Users work with a menu that allows them to seelct from a variety of
actions and queries surrounding the zoo residents. 

You can run this code by typing 'python zoo.py'
at the command prompt

Author: Anne Bracy (awb93) and Lillian Lee (ljl2)
Date:   April 5, 2019
"""

class Zoo():
    """
    A class representing a zoo, a collection of animals.

    INSTANCE ATTRIBUTES:
        name: the name of the zoo [str]
        animals: key-value collection of animals, keys are tag numbers, 
            values are the animals

    The deck attribute is assumed to hold enough Cards for the game
    to be able to run to completion (i.e. the deck wil not run out
    of cards for the player or dealer to draw).

    An instance is a zoo with a name and no animals.
    """
    # BUILT-IN METHODS
    def __init__(self, name):
        """
        Creates a new Zoo with no enclosures and no animals
        """
        # Instance attributes
        self.name = name
        self.animals = {}

    def listAnimals(self):
        """
        Prints out each animal in the zoo.
        """
        print("Here are the animals we've got:")
        for a in self.animals.values():
            print(a)

    def listenToAnimals(self):
        """
        Asks each animal in the zoo to speak.
        """
        print("We'll ask all the anmials to talk")
        for a in self.animals.values():
            print("hey "+a.name+", say something:")
            a.speak("Hi my name is "+a.name)

    def addAnimal(self):
        """
        Gets enough information from the user to create a new
        animal and add them to the zoo.
        """        
        type = input("What type of animal would you like to add? ")
        name = input("What's the animal's name? ")
        new_animal = None
        
        if type == "Animal":
            new_animal = Animal(name)
        elif type == "Fish":
            new_animal = Fish(name)
        elif type == "Parrot":
            new_animal = Parrot(name)
        elif type == "Bird":
            new_animal = Bird(name)
        elif type == "Penguin":
            new_animal = Penguin(name)
            
        if new_animal == None:
            "We can't add that type of animal"
        else:
            self.admit(new_animal)

    def populate(self):
        """
        Creates and adds a handful of animals to the zoo.
        """        
        a = Fish("Nemo")
        self.admit(a)
        a = Animal("Lassie")
        self.admit(a)
        a = Parrot("Polly")
        self.admit(a)
        a = Parrot("Alex")
        self.admit(a)
        a = Penguin("Chilly Willy")
        self.admit(a)
        a = Penguin("Pingu")
        self.admit(a)

    def admit(self, animal):
        """
        Given an animal, adds it to the zoo.

        animal: an object of type Animal
        """        
        
        assert(isinstance(animal, Animal))

        # put them on the animal list
        self.animals[animal.tag_no] = animal
        print("There are now "+str(len(self.animals))+" animals in "+self.name+".")

    def get_animal(self):
        """ A helper function that asks the user for a tag number
        and then finds that animal in the zoo

        Returns an object of type Animal or None if user specifies 
        a non-existant tag number.
        """
        tag_no = int(input("what's the TAG_NO of the animal in question? "))
        animal = None
        if tag_no in self.animals:
            animal = self.animals[tag_no]
        else:
            print("there is no animal with that tag number!")
        return animal

    def lookup(self):
        """
        User specifies the animal they're interested in.
        This function then prints out the information about the animal.
        """        
        animal = self.get_animal()
        print(animal)

    def feed(self):
        """
        User specifies the animal they're interested in.
        This function then feeds the animal.
        """        
        animal = self.get_animal()
        animal.eat()

    def print_menu(self):
        print("Welcome to "+self.name)
        print("\tWould you me like to:")
        print("\ta - add an animal to the zoo")
        print("\tb - list all the animals in the zoo")
        print("\tc - listen to all the animals in the zoo")
        print("\td - look up a specific animal in the zoo")
        print("\te - feed an animal in the zoo")
        print("\tf - pre-load a few animals")
        print("\tq - quit")

    def interact(self):
        """
        Simple loop that offers a menu of choices to a user
        so they can interact with the zoo.
        """        
        selection = ""
        while selection != 'q':
            if selection == 'a':
                self.addAnimal()
            elif selection == 'b':
                self.listAnimals()
            elif selection == 'c':
                self.listenToAnimals()
            elif selection == 'd':
                self.lookup()
            elif selection == 'e':
                self.feed()
            elif selection == 'f':
                self.populate()
            self.print_menu()
            selection = input("Your selection: ")

the_zoo = Zoo("the Hogle Zoo")

the_zoo.interact()
</pre></body></html>