Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
- 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:
- 1. 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.
- 2. 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.
- 3. 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.
- 4. 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.
- 5. 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.
- 6. 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.
- 7. Comment your code. Your comments should explain clearly what each part of the code does.
- 8. Include a main loop that is automatically called if the script is not imported by another script as a module.
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