Answered step by step
Verified Expert Solution
Link Copied!

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")
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

ISBN: 0262660709, 978-0262660709

More Books

Students also viewed these Databases questions

Question

state what is meant by the term performance management

Answered: 1 week ago