-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzoo.py
More file actions
187 lines (154 loc) · 5.48 KB
/
Copy pathzoo.py
File metadata and controls
187 lines (154 loc) · 5.48 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
class Animal:
"""
A class used to represent an animal
"""
zoo_name = "Hayaton"
def __init__(self, name, hunger=0):
"""Initializes the values name and hunger so that hunger default value is 0.
:param name: the name associated with the animal
:param hunger: the hunger level of the animal (if no value is given the value will be 0)
:type name: string
:type hunger: int
:return: None
"""
self._name = name
self._hunger = hunger
def get_name(self):
return self._name
def is_hungry(self):
"""Returns true if the animal is hungry (if hunger level > 0)
:return: whether or not the animal is hungry
:rtype: boolean
"""
return self._hunger > 0
def feed(self):
"""Decreases the hunger level of the animal by 1.
"""
self._hunger -= 1
def talk(self):
pass
class Dog(Animal):
def __init__(self, name, hunger):
"""Initializes the values name and hunger so that hunger default value is 0.
:param name: the name associated with the dog
:param hunger: the hunger level of the dog (if no value is given the value will be 0)
:type name: string
:type hunger: int
:return: None
"""
Animal.__init__(self, name, hunger)
# Overriding method
def talk(self):
"""Makes the dog say "woof woof"
"""
print("woof woof")
# Unique method
def fetch_stick(self):
print("There you go, sir!")
class Cat(Animal):
def __init__(self, name, hunger):
"""Initializes the values name and hunger so that hunger default value is 0.
:param name: the name associated with the cat
:param hunger: the hunger level of the cat (if no value is given the value will be 0)
:type name: string
:type hunger: int
:return: None
"""
Animal.__init__(self, name, hunger)
# Overriding method
def talk(self):
"""Makes the cat say "meow"
"""
print("meow")
# Unique method
def chase_laser(self):
print("Meeeeow")
class Skunk(Animal):
def __init__(self, name, hunger, stink_count=6):
"""Initializes the values name, hunger and stink_count so that\
hunger default value is 0 and stink_count default value is 6.
:param name: the name associated with the skunk
:param hunger: the hunger level of the skunk (if no value is given the value will be 0)
:param stink_count: the stink counter for the skunk (if no value is given the value will be 6)
:type name: string
:type hunger: int
:type stink_count: int
:return: None
"""
Animal.__init__(self, name, hunger)
self._stink_count = stink_count
# Overriding method
def talk(self):
"""Makes the skunk say "tsssss"
"""
print("tsssss")
# Unique method
def stink(self):
print("Dear lord!")
class Unicorn(Animal):
def __init__(self, name, hunger):
"""Initializes the values name and hunger so that hunger default value is 0.
:param name: the name associated with the unicorn
:param hunger: the hunger level of the unicorn (if no value is given the value will be 0)
:type name: string
:type hunger: int
:return: None
"""
Animal.__init__(self, name, hunger)
# Overriding method
def talk(self):
"""Makes the unicorn say "Good day, darling"
"""
print("Good day, darling")
# Unique method
def sing(self):
print("I’m not your toy...")
class Dragon(Animal):
def __init__(self, name, hunger, color="Green"):
"""Initializes the values name, hunger and color so that \
hunger default value is 0 and color default value is Green.
:param name: the name associated with the dragon
:param hunger: the hunger level of the dragon (if no value is given the value will be 0)
:param color: the color of the dragon (if no value is given the value will be "Green")
:type name: string
:type hunger: int
:type color: string
:return: None
"""
Animal.__init__(self, name, hunger)
self._color = color
# Overriding method
def talk(self):
"""Makes the dragon say "Raaaawr"
"""
print("Raaaawr")
# Unique method
def breath_fire(self):
print("$@#$#@$")
def main():
zoo_lst = [Dog("Brownie", 10), Cat("Zelda", 3), Skunk("Stinky", 0), Unicorn("Keith", 7),
Dragon("Lizzy", 1450), Dog("Doggo", 80), Cat(
"Kitty", 80), Skunk("Stinky Jr.", 80),
Unicorn("Clair", 80), Dragon("McFly", 80)]
# Iterate over the animals in the zoo
for animal in zoo_lst:
# print the animal's type and name
print(type(animal).__name__, animal.get_name())
# Feed the animal until it's full
while animal.is_hungry():
animal.feed()
animal.talk()
# Call the animal's unique method
if isinstance(animal, Dog):
animal.fetch_stick()
elif isinstance(animal, Cat):
animal.chase_laser()
elif isinstance(animal, Skunk):
animal.stink()
elif isinstance(animal, Unicorn):
animal.sing()
elif isinstance(animal, Dragon):
animal.breath_fire()
print("Zoo name:", Animal.zoo_name)
if __name__ == "__main__":
main()