Become A Pokemon Master

HI, below I public my code for “Become A Pokemon Master” practice. I will be grateful if you can check it and give me a constructive feedback :slight_smile:
FYI: im totalny noob :stuck_out_tongue:

# dictionar with pokemon type advantages, first type in value is stronger than second in pair 
pokemon_advantages = { 'adv_1': ["Fire", "Grass"], 'adv_2':["Water", "Fire"], 'adv_3': ["Grass", "Water"]  }

class Pokemon():
  def __init__(self, name, level, p_type): = name
    self.level = level
    self.p_type = p_type = 100 * level
    self.max_health = 100 * level
    self.exp = 0
    self.max_exp = 5 * level
    self.knocked_down = False

  def __repr__(self):
    return self.level
    return self.p_type
    return self.exp
    return self.knocked_down

  def knocked_out(self):
    self.knocked_down = True = 0
    print("{name} is knocked down.".format(name =

  def lose_health(self, lose_health): -= lose_health
    if > 0:
      print("{name} lose health! Curent health brings: {health} points".format(,
  def gain_health (self, add_health): += add_health
    if self.knocked_down == True: = 0
      print("{name} is KO!!! You should first revive Pokemon".format(
    elif < self.max_health:
      print("{name} recovered +{h} health points, current have {health} health points".format(h = add_health,,
    else: = self.max_health
      print("{name} recovered MAX health points, current have {health} health points".format(,
  def revive(self):
    if self.knocked_down == True:
      self.knocked_down = False = 100
      print ("{name} is revive!!!".format(name =
      print ("{name} current health points: {health}".format(name =, health =
      print("{p} is still alive.".format(p =
  def attack(self, other_p, ind = 20):
    if self.knocked_down == True or other_p.knocked_down == True:
      print("One of Pokemon's are KO, attack is not possible.")
      damage = (self.level*ind)/2
      for p1,p2 in pokemon_advantages.values():
        if self.p_type == p1 and other_p.p_type == p2:
          damage = 2 * self.level * ind
      print(" attack " + +" for "+str(damage))

  def exp_up(self):
    if self.exp < self.max_exp:
      print("{name} receive new exp points. Total exp points is {exp}.".format(, exp=self.exp))
      self.exp = 0
      self.level+= 1
      print("Congratulations {name} level up!!!. New level is {lvl}.".format(, lvl=self.level))

class Trainer(): 
  def __init__(self, name, pokemons, current_pokemon = "N/A"): = name
    self.pokemons = pokemons
    self.potions = int(len(pokemons))
    self.current_pokemon = current_pokemon

  def __repr__(self):

  def potion(self):
    self.potions -=1
    if self.potions > 0:
      pokemon = self.current_pokemon
      print("No potions.")
  def pick_p(self, pokemon):# set a current pokemon,
    print ("Available pokemons: "+ str(self.pokemons)+"\n""Your choice is {p}".format(p = pokemon))
    if pokemon in self.pokemons:
      if pokemon.knocked_down == False:
        self.current_pokemon = pokemon
        print ("{pokemon} is active pokemon".format(pokemon =
        print("You can't pick this pokemon, {p} is KO.".format(p = ))
      print("You can't pick this pokemon, {p} is not available for You.".format(p=

  def attack_other_trainer(self, other_trainer): # attack between current pokemons, belonging to two different trainers  
    if self.current_pokemon != "N/A" and other_trainer.current_pokemon!= "N/A" :
      print("{t1} pick {p1} and attack {t2} who pick to defence a {p2}".format(t1 =, p1 =, t2 =, p2 =
      if self.current_pokemon == "N/A" and other_trainer.current_pokemon == "N/A":
        print ("{t1} and {t2} should pick pokemons to fight.".format(t1 =, t2 =
      elif self.current_pokemon == "N/A":
        print ("{t1} should pick pokemon to fight.".format(t1 =
        print ("{t1} should pick pokemon to fight.".format(t1 =

  def add_p(self, new_p): # add new pokemon to trainer pocket with available pokemons
    if not new_p in  self.pokemons:
      print("{np} is added to Your pocket.".format(np =
      print("Current pocket:")
      print("You had {np} in pocket before.".format( np =   

# Test it :) 
a = Pokemon("Pokemon A", 1, "Fire")
b = Pokemon("Pokemon B", 1,"Grass")
c = Pokemon("Pokemon C", 1,"Water")
d = Pokemon("Pokemon D", 1,"Water")
t1 = Trainer("Trainer 1", [a,b,c,d])
t2 = Trainer("Trainer 2", [a,b,d])

1 Like


Some ideas:

It’d be nice to have some input option to interact with it. (not too hard to add given what you’ve done here). Could walk you through the prompt of picking pokemon and trainers to attack.

Some functions to list available pokemons, available trainers to attack, show current pokemons in pocket, display pokemon stats, would also be cool.

Hi @micro0381828704.

Have a close look at both __repr__ defintiions and perhaps try printing them, they may not work as you expect. I guess it’s because it’s a practice but be aware that you’ve used the same Pokemon instance objects for two different Trainer instances; attributes like health would effectively be shared. Worth having a once over of the potion method too, the order there seems a little off. Keep up the good work though.

Thanks for the feedback, I will be work on your tips :slight_smile:

I had a issue with input, but i resolve it and i will add this functionality and other new functions.

Can you expand what did you mean about repr. How it should look?
Mentioned to potion method, you have right I will change it.

I will be back with upgrade code. Give me a time :slight_smile:
Thanks A lot.

1 Like

Your __repr__ attribute should always return a string. If it doesn’t it will throw an error. Also be careful about how the return statement executes in a function. Statements following it won’t be of much use.