In this assignment, you will write aCatclass so that you can create a cat object and interact with it.
Create classCat. This class should have the following:
- Anameattribute that is intialized when a cat is created.
- Anenergyattribute that has an initial value of2.
- Astomachcapacity attribute that has an initial value of2.
- A method calledplay(). If the value ofenergyis greater than 0, it prints a message similar to "catname says meow" and then reduces the value of energy by 1. The message has to contain thenameof the cat and the soundmeow. However, if the value ofenergyis less than or equal to 0, it prints "catname is tired" instead.
- A method calledeat(). If the capacity ofstomachis greater than 0, it prints a message similar to "catname says nom" and then reduces the capacity of stomach by 1. The message has to contain thenameof the cat and the soundnom. However, if the capacity ofstomachis less than or equal to 0, it prints "catname is full" instead.
Inmain(), you should have the following:
- The program asks the user to enter a name and then creates a cat object with that name.
- The program then asks how the user would like to interact with the cat by entering either 'play' or 'feed'.
- Once the user enters the option, the program calls the corresponding methods from theCatclass to perform the interaction.
- Once the interaction is completed, the program should ask if the user would like to continue. If the user enters 'y', the program will again ask how the user would like to interact with the cat. If the user enters 'n', the program will end. The user can enter either a capital letter or a lowercase letter.
Before you start this assignment, make sure that you have:
- Completed all the course materials
- Run and understood all the sample code or exercise files
- Completed the labs in the previous modules
Program Template
Since this is a programming course, we will use a program to run a series of tests on your submission. Please download the template from the link below and modify it following the comments in the file to complete the assignment.
Test Before You Submit
To ensure that you get the best score you deserve for the assignment and not waste the submission attempts, make sure that you test your program thoroughly on your computer before you submit. Since this course is self-paced, you can take as long as necessary to perfect the program before submission.
Below is a screenshot of expected result from running the program. Compare your final result with the screenshot to verify. Look for small things such as upper or lower cases or extra white spaces, etc.
*Please note that if you are unable to get the template unzipped to please just use this alternate template to complete the assignment. It has to be exactly like the screenshot i provided in order for me to get credit because it is graded by an automatic grader
main.py file
fromcatimportCat
defmain():
choice ="y"
name = input("Please enter the name of your cat: ")
cat = Cat(........)
whilechoice =="y":
choice = input("How would you like to interact with {}? Enter 'play' or 'feed': ".format(name))
ifchoice =='..........':
cat.play()
else:
cat.eat()
choice = input("Would you like to continue? y/n: ").lower()
print("Goodbye!")
if__name__ =="__main__":
main()
cat.py file
classCat:
def__init__(self, name):
self.name = name
self.energy =.....
self.stomach_capacity =......
defplay(self):
ifself.energy >....:
print("{} says meow".format(self.name))
self.energy -=1
else:
print("{} is tired.".format(self.name))
defeat(self):
ifself.stomach_capacity >....:
print("{} says nom".format(self.name))
self.stomach_capacity -=1
else:
print("{} is full.".format(self.name))