-
Notifications
You must be signed in to change notification settings - Fork 0
/
critter_caretaker.242.py
81 lines (68 loc) · 1.79 KB
/
critter_caretaker.242.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Critter Caretaker
# a virtual pet to care for
# pg 242
class Critter(object):
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:
return "happy"
elif unhappiness <= 10:
return "okay"
elif unhappiness <= 15:
return "frusterated"
else:
return "mad"
def talk(self):
print('I am', 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 {}
2 - Feed {}
3 - Play with {}
""".format(crit_name, crit_name, crit_name))
choice = input('Choice:')
print()
#exit
if choice == '0':
print('Good bye')
#listen
elif choice == '1':
crit.talk()
#feed
elif choice == '2':
crit.eat()
#play
elif choice == '3':
crit.play()
#other unknown
else:
print('Make a valid choice.')
main()