forked from TheShubham-K/Python-Basic-Assessments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcourse_4_assessment_2.py
253 lines (200 loc) · 7.25 KB
/
course_4_assessment_2.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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# The class, Pokemon, is provided below and describes a Pokemon and its leveling and evolving characteristics. An instance of the class is one pokemon that you create.
# Grass_Pokemon is a subclass that inherits from Pokemon but changes some aspects, for instance, the boost values are different.
# For the subclass Grass_Pokemon, add another method called action that returns the string "[name of pokemon] knows a lot of different moves!". Create an instance of this class with the name as "Belle". Assign this instance to the variable p1.
class Pokemon(object):
attack = 12
defense = 10
health = 15
p_type = "Normal"
def __init__(self, name, level = 5):
self.name = name
self.level = level
def train(self):
self.update()
self.attack_up()
self.defense_up()
self.health_up()
self.level = self.level + 1
if self.level%self.evolve == 0:
return self.level, "Evolved!"
else:
return self.level
def attack_up(self):
self.attack = self.attack + self.attack_boost
return self.attack
def defense_up(self):
self.defense = self.defense + self.defense_boost
return self.defense
def health_up(self):
self.health = self.health + self.health_boost
return self.health
def update(self):
self.health_boost = 5
self.attack_boost = 3
self.defense_boost = 2
self.evolve = 10
def __str__(self):
self.update()
return "Pokemon name: {}, Type: {}, Level: {}".format(self.name, self.p_type, self.level)
class Grass_Pokemon(Pokemon):
attack = 15
defense = 14
health = 12
def update(self):
self.health_boost = 6
self.attack_boost = 2
self.defense_boost = 3
self.evolve = 12
def moves(self):
self.p_moves = ["razor leaf", "synthesis", "petal dance"]
class Grass_Pokemon(Pokemon):
def action(self):
return self.name + " knows a lot of different moves!"
p1 = Grass_Pokemon('Belle', 5)
#Modify the Grass_Pokemon subclass so that the attack strength for Grass_Pokemon instances does not change until they reach level 10. At level 10 and up, their attack strength should increase by the attack_boost amount when they are trained.
#To test, create an instance of the class with the name as "Bulby". Assign the instance to the variable p2. Create another instance of the Grass_Pokemon class with the name set to "Pika" and assign that instance to the variable p3. Then, use Grass_Pokemon methods to train the p3 Grass_Pokemon instance until it reaches at least level 10.
class Pokemon(object):
attack = 12
defense = 10
health = 15
p_type = "Normal"
def __init__(self, name, level = 5):
self.name = name
self.level = level
def train(self):
self.update()
self.attack_up()
self.defense_up()
self.health_up()
self.level = self.level + 1
if self.level%self.evolve == 0:
return self.level, "Evolved!"
else:
return self.level
def attack_up(self):
self.attack = self.attack + self.attack_boost
return self.attack
def defense_up(self):
self.defense = self.defense + self.defense_boost
return self.defense
def health_up(self):
self.health = self.health + self.health_boost
return self.health
def update(self):
self.health_boost = 5
self.attack_boost = 3
self.defense_boost = 2
self.evolve = 10
def __str__(self):
return "Pokemon name: {}, Type: {}, Level: {}".format(self.name, self.p_type, self.level)
class Grass_Pokemon(Pokemon):
attack = 15
defense = 14
health = 12
p_type = "Grass"
def update(self):
self.health_boost = 6
self.attack_boost = 2
self.defense_boost = 3
self.evolve = 12
def train(self):
self.update()
if self.level >= 10:
self.attack_up()
self.defense_up()
self.health_up()
self.level = self.level + 1
if self.level%self.evolve == 0:
return self.level, "Evolved!"
else:
return self.level
def moves(self):
self.p_moves = ["razor leaf", "synthesis", "petal dance"]
p2 = Grass_Pokemon("Bulby", level = 5)
p3 = Grass_Pokemon("Pika", level = 5)
p3.train()
#Along with the Pokemon parent class, we have also provided several subclasses. Write another method in the parent class that will be inherited by the subclasses. Call it opponent. It should return which type of pokemon the current type is weak and strong against, as a tuple.
# Grass is weak against Fire and strong against Water
# Ghost is weak against Dark and strong against Psychic
# Fire is weak against Water and strong against Grass
# Flying is weak against Electric and strong against Fighting
# For example, if the p_type of the subclass is 'Grass', .opponent() should return the tuple ('Fire', 'Water')
class Pokemon():
attack = 12
defense = 10
health = 15
p_type = "Normal"
def __init__(self, name,level = 5):
self.name = name
self.level = level
self.weak = "Normal"
self.strong = "Normal"
def train(self):
self.update()
self.attack_up()
self.defense_up()
self.health_up()
self.level = self.level + 1
if self.level%self.evolve == 0:
return self.level, "Evolved!"
else:
return self.level
def attack_up(self):
self.attack = self.attack + self.attack_boost
return self.attack
def defense_up(self):
self.defense = self.defense + self.defense_boost
return self.defense
def health_up(self):
self.health = self.health + self.health_boost
return self.health
def update(self):
self.health_boost = 5
self.attack_boost = 3
self.defense_boost = 2
self.evolve = 10
def __str__(self):
self.update()
return "Pokemon name: {}, Type: {}, Level: {}".format(self.name, self.p_type, self.level)
def opponent(self):
return self.weak, self.strong
class Grass_Pokemon(Pokemon):
attack = 15
defense = 14
health = 12
p_type = "Grass"
def __init__(self, name,level = 5):
self.name = name
self.level = level
self.weak = "Fire"
self.strong = "Water"
def update(self):
self.health_boost = 6
self.attack_boost = 2
self.defense_boost = 3
self.evolve = 12
class Ghost_Pokemon(Pokemon):
p_type = "Ghost"
def __init__(self, name,level = 5):
self.name = name
self.level = level
self.weak = "Dark"
self.strong = "Psychic"
def update(self):
self.health_boost = 3
self.attack_boost = 4
self.defense_boost = 3
class Fire_Pokemon(Pokemon):
p_type = "Fire"
def __init__(self, name,level = 5):
self.name = name
self.level = level
self.weak = "Water"
self.strong = "Grass"
class Flying_Pokemon(Pokemon):
p_type = "Flying"
def __init__(self, name,level = 5):
self.name = name
self.level = level
self.weak = "Electric"
self.strong = "Fighting"