Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Back in the 90s, there was a popular toy called a Giga Pet, a digital pet that you could care for and raise. We
Back in the 90s, there was a popular toy called a Giga Pet, a digital pet that you could care for and raise. We can create our own version of a Giga Pet using Python classes. Create a class PyPet with at least the following methods (feel free to add your own): . _init_(self) Create a PyPet care(self) Take care of the egg until it hatches, user should give the egg words of encouragement feed(self) Feed your pet status(self) Check whether your pet is hungry Your PyPet class should also track several attributes of your pet, at a minimum: hatched whether your egg has hatched hatched_time the time when your egg hatched start the time your pet was created validation number of times you have cared for your pet last_fed the time your pet was last fed times_fed total times your pet has been fed level level of pet name name of pet Your egg should hatch after criteria based on both the times it has been cared for as well as total time you have had the egg. Your pet should level up after criteria based on time owned and times fed. Implement your PyPet class in a program that allows the user to raise their own PyPet. In []: from time import time In [] class Pypet: definit__(self): self.name=input('What is the name of your pet? ') self.created_time = time() self.hatched = False def status (self): self.total_time = time () - self.created_time if (not self.hatched) & (self.total_time > 30): print (Congratulations, your egg has hatched! '). self.hatched = True self.hatched_time = time () if not self.hatched: print('{.0f} seconds have elapsed since you got your egg'.format(self.total_time)) print('{:.0f} seconds have elapsed since your egg hatched'.format(time() - self.hatched_time)). else: In [] pet1 = PyPet()
Step by Step Solution
★★★★★
3.26 Rating (144 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