def add_pokemon(self, pokemon: Pokemon): pokemons = [p for p in self.pokemon if p.name == pokemon] if pokemon in pokemons: return "This pokemon is already caught" self.pokemon.append(pokemon) return "Caught " + pokemon.pokemon_details()
from project.pokemon import Pokemon from project.trainer import Trainer pokemon = Pokemon("Pikachu", 90) print(pokemon.pokemon_details()) trainer = Trainer("Ash") print(trainer.add_pokemon(pokemon)) second_pokemon = Pokemon("Charizard", 110) print(trainer.add_pokemon(second_pokemon)) print(trainer.add_pokemon(second_pokemon)) print(trainer.release_pokemon("Pikachu")) print(trainer.release_pokemon("Pikachu")) print(trainer.trainer_data())
def add_pokemon(self, pokemon: Pokemon): if pokemon.pokemon_details() not in self.pokemon: self.pokemon.append(pokemon.pokemon_details()) return f'Caught {pokemon.name} with health {pokemon.health}' else: return f'This pokemon is already caught'