Please help me with this python work InfoTc 1040 Introduction to Problem Solving
ID: 3603335 • Letter: P
Question
Please help me with this python work
InfoTc 1040 Introduction to Problem Solving and Programming Animal Class In this programming assignment, you are going to create a class named Animal that is used to store information about an animal. You will then create a program that takes user input, allowing the user to create multiple Animal objects. Finally, you will retrieve the information stored in those objects and display it. Animal Class Write a class named Animal that has the following attributes and methods. Save this class as Animal.py Attributes animal_type: a hidden attribute used to indicate the animal's type. For example: gecko, walrus, tiger, etc. name: a hidden attribute used to indicate the animal's name. mood: a hidden attribute used to indicate the animal's mood. For example: happy, hungry, or sleepy. Methods _ in it-: this method should create the three attributes above and assign their default values. The value of__mood should be set randomly. Generate a random number between 1 and 3. Then If the number is 1, the__mood field should be set to a value of "happy". If the number is 2, the__mood field should be set to a value of "hungry". If the number is 3, the__mood field should be set to a value of "sleepy". get_animal_type: this method should return the value of the -animal-type field. get_name: this method should return the value of the__name field. check_mood: this method should return the value of the__mood field.Explanation / Answer
Animal.py
from random import randint
class Animal:
def __init__(self, animal_type, animal_name):
self.__animal_type = animal_type
self.__name = animal_name
r = randint(1, 3)
if r == 1:
self.__mood = "happy"
elif r == 2:
self.__mood = "hungry"
else:
self.__mood = "sleepy"
def get_animal_type(self):
return self.__animal_type
def get_name(self):
return self.__name
def check_mood(self):
return self.__mood
# copy patsable link: https://paste.ee/p/RsGEE
animalGenerator.py
from Animal import Animal
print("Welcome to the animal generator!")
print("This program creates Animal objects")
animal_list = []
while(True):
animal_type = input("What type of animal you like to create? ")
animal_name = input("What is the animal's name? ")
animal_list.append(Animal(animal_type, animal_name))
print()
choice = input("Would you like to add more animals (y/n)? ")
print()
if choice == "n":
break
if len(animal_list):
print("Animal List")
print("-----------")
for animal in animal_list:
print(animal.get_name() + " the " + animal.get_animal_type() + " is " + animal.check_mood())
# copy patsable code link: https://paste.ee/p/KYIAO
Sample run
Welcome to the animal generator!
This program creates Animal objects
What type of animal you like to create? Gecko
What is the animal's name? Gordon
Would you like to add more animals (y/n)? y
What type of animal you like to create? Walrus
What is the animal's name? Wally
Would you like to add more animals (y/n)? y
What type of animal you like to create? Tiger
What is the animal's name? Truman
Would you like to add more animals (y/n)? n
Animal List
-----------
Gordon the Gecko is hungry
Wally the Walrus is happy
Truman the Tiger is happy
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.