GymBattle.py #1n Pokemon Go, a Pokemon is defined by several different 2 #parame
ID: 3919761 • Letter: G
Question
GymBattle.py #1n Pokemon Go, a Pokemon is defined by several different 2 #parameters. For simplicity in this problem, we'll say that 3 #every Pokemo 4 #string, and its power level, an integer. n is defined by two parameters: its name, a 6 #create a class called Pokemon. The Pokemon class's 7 fconstructor should have two parameters (in addition to self) 8 #th e Pokemon's name and the Pokemon 's power. These should be 9 Wassigned to attributes called name and power 10 # 11 #The Pokemon class should also have a method called 12 ????0uld, defeat. would-defeat will have one parameter: an 13. #instance of adifferentPokemon. woulddefeat should - - - is Pokemon' s power is greater than the 15 fother Pokemon's power, or False if not. 16 17 18 #Add your code here 19 21 22 #Below 23 #You can change these lines to test your code in different 24 ways. 25 # 26 #1f your code works correctly, this will originally run 27 #error-free and print: 28 Pikachu 29 : #500 30 ralse are some 1ines of code that will test your object 31 #True 32 new pokemon 1 Pokemon(Pikachu 500) 33 print (new pokemon 1. name) 34 print (new pokemon 1.powe) 35 36 new pokemon 2 Pokemon (Charizard 2422) 37 new pokemon 3 Pokemon Squirtien.322) 38 print (new pokemonl1 would de Feat( new pokemon 2)) 39 print (new pokemon l.would de feat(new pokemon 3)) 40Explanation / Answer
class Pokemon: def __init__(self, name, power): self.name = name self.power = power def would_defeat(self, a_different_pokemon): return self.power > a_different_pokemon.power 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))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.