Advertisement
exDotaPro

pokemon

Oct 27th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. class Pokemon:
  2.     def __init__(self, name: str, health: int):
  3.         self.name = name
  4.         self.health = health
  5.  
  6.     def pokemon_details(self):
  7.         return f'{self.name} with health {self.health}'
  8.  
  9.  
  10. from project.pokemon import Pokemon
  11.  
  12.  
  13. class Trainer:
  14.     def __init__(self, name: str, pokemon_details=None):
  15.         if pokemon_details is None:
  16.             pokemon_details = []
  17.         self.name = name
  18.         self.pokemon_details = pokemon_details
  19.  
  20.     def add_pokemon(self, pokemon: Pokemon):
  21.         if pokemon.name in self.pokemon_details:
  22.             return 'This pokemon is already caught'
  23.         self.pokemon_details.append(pokemon.pokemon_details())
  24.         return 'Caught ' + pokemon.pokemon_details()
  25.  
  26.     def release_pokemon(self, pokemon_name: str):
  27.         for p in self.pokemon_details:
  28.             if pokemon_name in p:
  29.                 self.pokemon_details.remove(p)
  30.                 return f'You have released {pokemon_name}'
  31.             return 'Pokemon is not caught'
  32.  
  33.     def trainer_data(self):
  34.         trainer_info = [
  35.             f'Pokemon Trainer {self.name}',
  36.             f'Pokemon count {len(self.pokemon_details)}'
  37.         ]
  38.         pokemon_info = [f'- {p}' for p in self.pokemon_details]
  39.  
  40.         return f'\n'.join(trainer_info + pokemon_info)
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement