Question: class Zoo: def __init__(self): # This dictionary holds the counts of animals in the zoo. # ex. {lion: 5, monkey:12, zebra:9, elephant:0} self.animals = {}

class Zoo:
def __init__(self):
# This dictionary holds the counts of animals in the zoo.
# ex. {"lion": 5, "monkey":12, "zebra":9, "elephant":0}
self.animals = {}
def add_animal(self, animal):
animal = animal.lower()
'''
Accepts as a string the name of an animal and adds it to the dictionary.
It must accept a string in any case, and still count as the same type of animal.
Example:
z = Zoo()
z.add_animal("lion")
z.add_animal("Lion")
z.add_animal("LION")
>> {"lion":3}
'''
pass
def remove_animal(self, animal):
'''
Removes an animal from the inventory.
The count for an animal can reach zero, however, it cannot go below.
'''
pass
def add_animal_list(self, animal_list):
'''
Accepts a list of animals that are being brought to the zoo. The dictionary
will be updated.
ex. add_animal_list(["lion", "lion", "monkey", "python"])
'''
pass
def zoo_count(self):
'''
Returns the number of animals in the zoo.
'''
pass
def highest_count(self):
'''
Returns the name of the animal that there is the most of at the zoo.
'''
pass
def as_string(self):
'''
Returns a string of the counts of animals. It does NOT print, it returns a string.
Each animal should be on its own line.
Example:
print( z.as_string())
lion: 5
monkey:12
zebra:9
elephant:0
'''
pass
z = Zoo()
# Test adding animals
# z.add_animal("lion")
# z.add_animal("LION")
# z.add_animal("zebra")
# prints the internal dictionary.
print(z.animals)
# Test removing animals
# z.remove_animal("lion")
# z.remove_animal("zebra")
# z.remove_animal("zebra")
 class Zoo: def __init__(self): # This dictionary holds the counts of

The Zoo object is made of an internal dictionary that holds the count of each animal at the zoo. Task Complete the methods for the Zoo object as they are described in the starter code. Note that there are no built-in tests for your code. You are required to create your own tests in order to verify correctness. I have induded a few to get you started (you will have to uncomment them.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!