The zoo will have several animals, and each animal will have a name, age, and species. Moreover, each animal will have a method make_sound(), which should return a string representing the sound it makes. Perform the following steps: Create a Zoo class. This class should be able to store multiple animals. It should have methods to add_animal and remove_animal. Also, add a method get_animals that prints a list of all animals currently in the zoo, including their name, age, and species. Create an Animal parent class. This class should have attributes for name, age, and species. Include a make_sound() method that returns a string representing the sound the animal makes. Create two or more child classes that inherit from Animal (for example, Lion and Elephant - you get to choose the animal types). These child classes should override the make_sound() method to return a sound specific to the animal they represent. Your program should be interactive. It should provide a menu to the user that allows them to add an animal to the zoo, remove an animal from the zoo, or list all animals in the zoo. The user should be able to keep using this menu until they decide to quit the program. When adding an animal, your program should ask the user for the animal's name, age, and type. It should then create an object of the appropriate type, and add it to the zoo. Ensure that your program handles errors appropriately. For example, it should not crash if the user tries to remove an animal that isn't in the zoo. Comment your code. Your comments should explain clearly what each part of the code does. Include a main loop that is automatically called if the script is not imported by another script as a module. Hint: You can use the input() function to get input from the user, and a loop to keep showing the menu until the user decides to quit. You may want to use a dictionary to map from animal types entered by the user to your animal classes.
The zoo will have several animals, and each animal will have a name, age, and species. Moreover, each animal will have a method make_sound(), which should return a string representing the sound it makes. Perform the following steps: Create a Zoo class. This class should be able to store multiple animals. It should have methods to add_animal and remove_animal. Also, add a method get_animals that prints a list of all animals currently in the zoo, including their name, age, and species. Create an Animal parent class. This class should have attributes for name, age, and species. Include a make_sound() method that returns a string representing the sound the animal makes. Create two or more child classes that inherit from Animal (for example, Lion and Elephant - you get to choose the animal types). These child classes should override the make_sound() method to return a sound specific to the animal they represent. Your program should be interactive. It should provide a menu to the user that allows them to add an animal to the zoo, remove an animal from the zoo, or list all animals in the zoo. The user should be able to keep using this menu until they decide to quit the program. When adding an animal, your program should ask the user for the animal's name, age, and type. It should then create an object of the appropriate type, and add it to the zoo. Ensure that your program handles errors appropriately. For example, it should not crash if the user tries to remove an animal that isn't in the zoo. Comment your code. Your comments should explain clearly what each part of the code does. Include a main loop that is automatically called if the script is not imported by another script as a module. Hint: You can use the input() function to get input from the user, and a loop to keep showing the menu until the user decides to quit. You may want to use a dictionary to map from animal types entered by the user to your animal classes.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
- The zoo will have several animals, and each animal will have a name, age, and species. Moreover, each animal will have a method make_sound(), which should return a string representing the sound it makes. Perform the following steps:
- Create a Zoo class. This class should be able to store multiple animals. It should have methods to add_animal and remove_animal. Also, add a method get_animals that prints a list of all animals currently in the zoo, including their name, age, and species.
- Create an Animal parent class. This class should have attributes for name, age, and species. Include a make_sound() method that returns a string representing the sound the animal makes.
- Create two or more child classes that inherit from Animal (for example, Lion and Elephant - you get to choose the animal types). These child classes should override the make_sound() method to return a sound specific to the animal they represent.
- Your program should be interactive. It should provide a menu to the user that allows them to add an animal to the zoo, remove an animal from the zoo, or list all animals in the zoo. The user should be able to keep using this menu until they decide to quit the program.
- When adding an animal, your program should ask the user for the animal's name, age, and type. It should then create an object of the appropriate type, and add it to the zoo.
- Ensure that your program handles errors appropriately. For example, it should not crash if the user tries to remove an animal that isn't in the zoo.
- Comment your code. Your comments should explain clearly what each part of the code does.
- Include a main loop that is automatically called if the script is not imported by another script as a module.
- Hint: You can use the input() function to get input from the user, and a loop to keep showing the menu until the user decides to quit. You may want to use a dictionary to map from animal types entered by the user to your animal classes.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 5 images
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
when I input tiger it does not print Invalid animal type. I have tried to rearrage the code multiple times, but I cant seem to get it to work correctly. Do you know how to fix this?
Solution
by Bartleby Expert
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education