The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 313 Weeks Ago, 4 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
# 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.\n")
       self.__pass_time()
  Â
   def eat(self, food = 4):
       print("Brruppp. Thank you.")
       self.hunger -= food
       if self.hunger < 0:
           self.hunger = 0
       self.__pass_time()
Â
   def play(self, fun = 4):
       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
       elif choice == "2":
           crit.eat()
       Â
       # play with your critter
       elif choice == "3":
           crit.play()
Â
       # some unknown choice
       else:
           print("\nSorry, but", choice, "isn't a valid choice.")
Â
main()
("\n\nPress the enter key to exit.")
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly