Using the Python program text code and .py..... Modify the Critter caretaker pro
ID: 3713568 • Letter: U
Question
Using the Python program text code and .py..... Modify the Critter caretaker program by allowing the user to specify how much food the Critter is fed and how long it is played with. These values should then trigger a change in the way the critters hunger and boredom levels change.
Play with your critter C:Python31 1python.exe Choice: 3 Uheee! Critter Caretaker e Quit 1 Listen to your critter 2 Feed your critter 3 Play with your critter Choice: 1 'n Larry and I feel happy now. Critter Caretaker 0 Quit 1Listen to your critter 2 Feed your critter 3 Play with your critterExplanation / Answer
Hi Dear,
you have not posted python code that I have to modify. I have implemented my own.
# Critter Caretaker
# A virtual pet to care for
class Critter(object):
"""A virtual pet"""
def __init__(self, name, hunger = 0, boredom = 0):
self.name = name
self.hunger = hunger
self.boredom = boredom
def __pass_time(self):
self.hunger += 1
self.boredom += 1
@property
def mood(self):
unhappiness = self.hunger + self.boredom
if unhappiness < 5:
m = "happy"
elif 5 <= unhappiness <= 10:
m = "okay"
elif 11 <= unhappiness <= 15:
m = "frustrated"
else:
m = "mad"
return m
def talk(self):
print("I'm", self.name, "and I feel", self.mood, "now. ")
self.__pass_time()
def eat(self, food):
print("Brruppp. Thank you.")
self.hunger -= food
if self.hunger < 0:
self.hunger = 0
self.__pass_time()
def play(self, fun):
print("Wheee!")
self.boredom -= fun
if self.boredom < 0:
self.boredom = 0
self.__pass_time()
def main():
crit_name = input("What do you want to name your critter?: ")
crit = Critter(crit_name)
choice = None
while choice != "0":
print
("""
Critter Caretaker
0 - Quit
1 - Listen to your critter
2 - Feed your critter
3 - Play with your critter
""")
choice = input("Choice: ")
print()
# exit
if choice == "0":
print("Good-bye.")
# listen to your critter
elif choice == "1":
crit.talk()
# feed your critter
#enter some value with the function
elif choice == "2":
crit.eat(6)
# play with your critter
#enter some value with the function
elif choice == "3":
crit.play(5)
# some unknown choice
else:
print(" Sorry, but", choice, "isn't a valid choice.")
main()
(" Press the enter key to exit.")
The amount they eat is equal to the number you put into the function ( i have put 6 and 5 as examples), You can put variables as well.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.