Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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")
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started