Question
Please help me with this Python program And there are previous code # Animal.py # This program defines the Animal class import random class Animal:
Please help me with this Python program
And there are previous code
# Animal.py # This program defines the Animal class
import random
class Animal: # Define what happens when a new animal object is created def __init__(self, animal_type, animal_name): self.__animal_type = animal_type self.__name = animal_name
# Pick a number between 1 and 3 random_number = random.randint(1, 3)
# Set the animal's mood based on the random number if random_number == 1: self.__mood = "happy" elif random_number == 2: self.__mood = "hungry" elif random_number == 3: self.__mood = "sleepy"
# Return the animal's type def get_animal_type(self): return self.__animal_type
# Return the animal's name def get_name(self): return self.__name
# Return the animal's mood def check_mood(self): return self.__mood
# copy pastable code link:https://paste.ee/p/o8BxD
# Program: animalGenerator.py # This program creates and displays information about Animal objects.
import Animal
# Create a list for Animal objects animals = []
# Print a welcome message print("Welcome to the animal generator!") print("This program creates Animal objects")
while True: # Ask the user for the animal's type and name animal_type = input(" What type of animal would you like to create? ") animal_name = input("What is the animal's name? ")
# Create a new Animal object animal = Animal.Animal(animal_type, animal_name)
# Append the Animal object to the list animals.append(animal)
# Ask the user if they would like to continue creating animals choice = input(" Would you like to add more animals (y)? ") if choice != "y": break
# Print a header print(" Animal List") print("-----------")
# Loop through the list for animal in animals: # Use accessor methods to get each Animal object's information animal_name = animal.get_name() animal_type = animal.get_animal_type() animal_mood = animal.check_mood()
# Print the Animal object's information print(animal_name, "the", animal_type, "is", animal_mood)
# copy pastable code link:https://paste.ee/p/iszDl
InfoTc 1040 Introduction to Problem Solving and Programming Animal Subclass In this programming assignment, you are going to create two subclasses of the Animal class that is used to store information about either a mammal or a bird. You will then extend a program that takes user input, allowing the user to create multiple Mammal or Bird objects. Finally, you will retrieve the information stored in those objects and display it. Mammal Class Write a class named Mammal that inherits from Animal class that has the following additional attribute and method. This class should be written in the Animal.py file. Attributes hair color:a hidden attribute used to indicate the color of the mammal's hair Methods init__:this method should initialize the two attributes from the Animal class required in the Animal class'_init the single attribute listed above, and assign their default values. get hair_color: this method should return the value of the hair_color field. Bird Class Write a class named Bird that inherits from Animal class that has the following additional attribute and method. This class should be written in the Animalpy file Attributes can_fly: a hidden attribute used to indicate if the bird can fly Methods init : this method should initialize the two attributes from the Animal class required in the Animal class'_init_ the single attribute listed above, and assign their default values. get_can_fly: this method should return the value of the__can_fly fieldStep 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