Answered step by step
Verified Expert Solution
Question
1 Approved Answer
write a Cat class so that you can make a cat object and interact with it. Make a class Cat. This class should have
write a Cat class so that you can make a cat object and interact with it. Make a class Cat. This class should have the following: A name attribute that is intialized when a cat is created. An energy attribute that has an initial value of 2. A stomach capacity attribute that has an initial value of 2. A method called play(). If the value of energy is 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 the name of the cat and the sound meow. However, if the value of energy is less than or equal to 0, it prints "catname is tired" instead. A method called eat(). If the capacity of stomach is 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 the name of the cat and the sound nom. However, if the capacity of stomach is less than or equal to 0, it prints "catname is full" instead. In main(), 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 the Cat class 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. Below is a screenshot of expected result from running the program. Compare your nal result with the screenshot to verify. Look for small things such as upper or lower cases or extra white spaces, etc. Python 3.9.4 (v3.9.4:1f2e3088f3, Apr 4 2021, 12:32:44) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license()" for more information. >>> == RESTART: /Users/zli8/Desktop/Programming Assignment 2/main.py Please enter the name of your cat: Blossom How would you like to interact with Blossom? Enter 'play' or 'feed': play Blossom says meow Would you like to continue? y/n: y How would you like to interact with Blossom? Enter 'play' or 'feed': play Blossom says meow Would you like to continue? y/n: y How would you like to interact with Blossom? Enter 'play' or 'feed': play Blossom is tired. Would you like to continue? y/n: y How would you like to interact with Blossom? Enter 'play' or 'feed': feed Blossom says nom Would you like to continue? y/n: y How would you like to interact with Blossom? Enter 'play' or 'feed': feed Blossom says nom Would you like to continue? y/n: y How would you like to interact with Blossom? Enter 'play' or 'feed': feed Blossom is full. Would you like to continue? y/n: n Goodbye! >>> | write a Cat class so that you can make a cat object and interact with it. Make a class Cat. This class should have the following: A name attribute that is intialized when a cat is created. An energy attribute that has an initial value of 2. A stomach capacity attribute that has an initial value of 2. A method called play(). If the value of energy is 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 the name of the cat and the sound meow. However, if the value of energy is less than or equal to 0, it prints "catname is tired" instead. A method called eat(). If the capacity of stomach is 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 the name of the cat and the sound nom. However, if the capacity of stomach is less than or equal to 0, it prints "catname is full" instead. In main(), 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 the Cat class 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. Below is a screenshot of expected result from running the program. Compare your nal result with the screenshot to verify. Look for small things such as upper or lower cases or extra white spaces, etc. Python 3.9.4 (v3.9.4:1f2e3088f3, Apr 4 2021, 12:32:44) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license()" for more information. >>> == RESTART: /Users/zli8/Desktop/Programming Assignment 2/main.py Please enter the name of your cat: Blossom How would you like to interact with Blossom? Enter 'play' or 'feed': play Blossom says meow Would you like to continue? y/n: y How would you like to interact with Blossom? Enter 'play' or 'feed': play Blossom says meow Would you like to continue? y/n: y How would you like to interact with Blossom? Enter 'play' or 'feed': play Blossom is tired. Would you like to continue? y/n: y How would you like to interact with Blossom? Enter 'play' or 'feed': feed Blossom says nom Would you like to continue? y/n: y How would you like to interact with Blossom? Enter 'play' or 'feed': feed Blossom says nom Would you like to continue? y/n: y How would you like to interact with Blossom? Enter 'play' or 'feed': feed Blossom is full. Would you like to continue? y/n: n Goodbye! >>> |
Step by Step Solution
★★★★★
3.41 Rating (151 Votes )
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