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): 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()
def __init__(self, name: str): self.name = name self.pokemon = [] 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' def release_pokemon(self, pokemon_name: str): for p in self.pokemon: if pokemon_name in p: self.pokemon.remove(p) return f'You have released {pokemon_name}' else: return 'Pokemon is not caught' def trainer_data(self): result = f'Pokemon Trainer {self.name}\nPokemon count {len(self.pokemon)}\n' for p in self.pokemon: result += f'- {p}' return result trainer = Trainer("Stamat") pokemon = Pokemon("Pesho", 90) trainer.add_pokemon(pokemon) 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'
from project.pokemon import Pokemon from project.trainer import Trainer pokemon = Pokemon("Pikachu", 90) pokemon2 = Pokemon("Pikachu2", 90) trainer = Trainer("Ash") print(trainer.add_pokemon(pokemon)) print(trainer.add_pokemon(pokemon2)) print(trainer.trainer_data())