-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGymBattle.py
More file actions
49 lines (43 loc) · 1.59 KB
/
Copy pathGymBattle.py
File metadata and controls
49 lines (43 loc) · 1.59 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
# In Pokemon Go, a Pokemon is defined by several different
# parameters. For simplicity in this problem, we'll say that
# every Pokemon is defined by two parameters: its name, a
# string, and its power level, an integer.
#
# Create a class called Pokemon. The Pokemon class's
# constructor should have two parameters (in addition to self):
# the Pokemon's name and the Pokemon's power. These should be
# assigned to attributes called 'name' and 'power'.
#
# The Pokemon class should also have a method called
# would_defeat. would_defeat will have one parameter: an
# instance of a _different_ Pokemon. would_defeat should
# return True if this Pokemon's power is greater than the
# other Pokemon's power, or False if not.
# Add your code here!
class Pokemon:
def __init__(self, name, power):
self.name = name
self.power = power
def would_defeat(self, new_pokemon):
# Compare the first pokemon's with the new_pokemon.
if self.power > new_pokemon.power:
return True
else:
return False
# Below are some lines of code that will test your object.
# You can change these lines to test your code in different
# ways.
#
# If your code works correctly, this will originally run
# error-free and print:
# Pikachu
# 500
# False
# True
new_pokemon_1 = Pokemon("Pikachu", 500)
print(new_pokemon_1.name)
print(new_pokemon_1.power)
new_pokemon_2 = Pokemon("Charizard", 2412)
new_pokemon_3 = Pokemon("Squirtle", 312)
print(new_pokemon_1.would_defeat(new_pokemon_2))
print(new_pokemon_1.would_defeat(new_pokemon_3))