from zoology import Animal, Parrot, Bird, Penguin """ Author: Anne Bracy (awb93) and Lillian Lee (ljl2) Date: April 16, 2018 """ """ You can run this code by typing 'python zoo.py' At the command prompt """ class Zoo(): """ An instance is a zoo with no enclosures 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.enclosures = {} self.animals = {} def list_enclosures(self): print("Here are the enclosures we've got:") for a_type in self.enclosures.keys(): print("In the "+a_type.__name__+" enclosure: ") for a in self.enclosures[a_type]: print(str(a)) if a_type.CAN_FLY: print("this enclosure needs to be very tall!") def list_animals(self): print("Here are the animals we've got:") for a in self.animals.values(): print(a) def admit(self, animal): assert(isinstance(animal, Animal)) # put them on the animal list self.animals[animal.tag_no] = animal # put them in the correct enclosure a_type = type(animal) if a_type in self.enclosures: right_enclosure = self.enclosures[a_type] right_enclosure.append(animal) else: self.enclosures[a_type] = [animal] def lookup(self, tag_no): animal = None try: animal = self.animals[tag_no] except: print("there is no animal with that tag number!") return animal def print_menu(): print("\tWould you me like to:") print("\ta - list all the animals in the zoo") print("\tb - list all the animals in each enclosure") print("\tc - give an animal a new name") print("\tq - quit") def interact(self): print("Welcome to "+self.name) selection = "" while selection != 'q': if selection == 'a': self.list_animals() elif selection == 'b': self.list_enclosures() elif selection == 'c': tag_no = int(input("what's the TAG_NO of the animal in question? ")) animal = self.lookup(tag_no) if animal != None: new_name = input("what name would you like to give this animal? ") animal.set_name(new_name) Zoo.print_menu() selection = input("Your selection: ") the_zoo = Zoo("the Hogle Zoo") the_zoo.admit(Animal()) the_zoo.admit(Animal("Lassie")) the_zoo.admit(Bird("Sweetie")) the_zoo.admit(Parrot("Alex")) the_zoo.admit(Penguin("Pingu")) the_zoo.interact()