In this lab, you will be building a simulation of a virtual zoo using object-oriented programming (OOP) principles in Python. The goal of this lab is to practice defining base and derived classes, using constructors, and method overriding.
- fork and clone this repo, cd into the new folder
- use
zoo.pyto complete the assignment
Create a base Animal class that has the following properties:
- name
- species
- age
- gender
Add the following methods:
describe-- prints out all information about the animalfeed-- prints out"< animal name > is eating"make_sound-- prints out"< animal name > is making a sound"move-- prints out"< animal name > is moving"
Create the following child class that derives from the base Animal class, adding properties and
using method override when needed:
Mammal-- has afur_colorproperty that is printed out in it's description- drinks milk when feeding
- walks when moving
- growls when making a sound
Create a Zoo class with an animals property that is a list of all of the animals in the zoo.
The Zoo class should have the following methods:
add_animal-- adds an animal to the listdisplay_animals-- displays information for all animalsfeed_animals-- feeds all animalslisten_to_animals-- listens to all the animalswatch_animals-- watches the animals move around
Create additional child classes to populate your zoo!
Bird-- has awingspanproperty that is printed out in it's description- drinks nectar when feeding
- flies when moving
- chirps when making a sound
Reptile-- has ascale_colorproperty that is printed out in it's description- eats insects when feeding
- slithers when moving
- hisses when making a sound
Example code:
zoo = Zoo()
lion = Mammal("Simba", "Lion", 5, "male", "golden")
snake = Reptile("Kaa", "Snake", 4, "female", "green") # example bonus reptile
lion.make_sound()
# > Simba is making a sound
# > Simba is growling
zoo.add_animal(lion)
zoo.add_animal(snake)
zoo.feed_animals()
# > Simba is eating
# > Simba is drinking milk
# > Kaa is eating
# > Kaa is eating insectsWrite similar code chunks to test your zoo's methods and the various animals you create.