My solution to the Codecademy Pro Project “Become A Pokemon Master!”. Create a Pokemon Class and a Trainer Class in Python, adding functionality to include healing, battle damage, level ups and evolves! Note – lovers of the official characters will probably be horrified to learn I’ve just assigned the Pokemon random stats. This is just for fun!

class Pokemon:
  def __init__(self, name='Default', level=1, element='Grass', maxhealth=100, curr_health=10, concious=True, attack=1, defence=1, speed=1): = name
    self.level = level
    self.element = element
    self.maxhealth = maxhealth
    self.curr_health = curr_health
    self.concious = concious
    self.attack = attack
    self.defence = defence
    self.speed = speed
    self.experience = 0
    #establishes advantages for the pokemon on instantiation
    if self.element == 'Fire':
      self.disadvantage = 'Water'
      self.advantage = 'Grass'
    elif self.element == 'Water':
      self.disadvantage = 'Grass'
      self.advantage = 'Fire'
      self.advantage = 'Water'
      self.disadvantage = 'Fire'

  def __repr__(self):
    return 'Pokemon Object {}'.format(

  #method for displaying pokemon status
  def status(self):
    print('Current stats for {}:\n'.format(
    print('Level: {}'.format(self.level))
    print('Element: {}'.format(self.element))
    print('Max Health: {}'.format(self.maxhealth))
    print('Current Health: {}'.format(self.curr_health))
    print('ATK: {}  DEF: {} SPEED: {}'.format(self.attack, self.defence, self.speed))
    print('XP: {}'.format(self.experience))
    if not self.concious:
      print('Awareness: Unconcious')
      print('Awareness: Concious')
    print('Has advantage over {} Pokemon.'.format(self.advantage))
    print('Has disadvantage against {} Pokemon.\n'.format(self.disadvantage))

  #method to render pokemon unconcious
  def ko(self):
    if not self.concious:
      print('{} is already unconcious!\n'.format(
      print('{} is rendered unconcious!\n'.format(
      self.concious = False
      self.curr_health = 0

  #method to revive pokemon from unconciousness
  def revive(self):
    if self.concious:
      print('{} is already concious!\n'.format(
      print('{} is revived!\n'.format(
      self.concious = True

  #method to calculate the effects of damage
  def damage(self, damage):
    if damage >= self.curr_health:
      print('{} takes {} damage!\n'.format(, damage))
      self.curr_health -= damage
      print('{} takes {} damage and has {} health remaining.\n'.format(, damage, self.curr_health))

  #method to calculate the effects of healing
  def heal(self, heal):
    if self.curr_health + heal >= self.maxhealth:
      print('{} is healed to max health!\n'.format(
      self.curr_health = self.maxhealth
      self.curr_health += heal
      print('{} is healed for {} hit points and now has {} remaining.\n'.format(, heal, self.curr_health))
    if not self.concious:

  #method to calculate the effects of battle, according to advantages
  def defend(self, pokemon):
    print('{} is attacked by {}!'.format(,
    #implement benefits provided by stats
    damage = (pokemon.level + pokemon.attack)
    if self.disadvantage == pokemon.element:
      self.damage((damage * 2) - self.defence)
    elif self.advantage == pokemon.element:
      self.damage(round(damage / 2) - self.defence)
      self.damage(damage - self.defence)

  #method to handle experience gain and manage levels
  def addxp(self, xp):
    self.experience += xp
    #checks for level up and retains excess experience
    if self.experience >= 500:
      self.experience -= 500
      self.level += 1
      print('{} has levelled up and is now level {}!\n'.format(, self.level))
   #evolves every 5 levels
      if self.level % 5 == 0:

  def evolve(self):
    print('{} has evolved, +1 added to all stats!'.format(
    self.attack += 1; self.defence += 1; self.speed += 1

class Trainer:
  def __init__(self, name='Default', pokemons=None, potions=0, active=1): = name
    self.potions = potions
    if pokemons is None:
      self.pokemons = [] = None
      self.pokemons = pokemons = self.pokemons[active - 1]
    #cuts list if more than 6 pokemon in list
    while len(self.pokemons) > 6:
      print('Too many Pokemon! {} is cut from {}\'s roster.\n'.format((self.pokemons.pop()).name,

  def __repr__(self):
    print('Pokemon Trainer Object {}'.format(
  #display trainer status
  def status(self):
    print('Current stats for {}:\n'.format(
    print('Potions Remaining: {}'.format(self.potions))
    if self.pokemons:
      print('Active Pokemon: {}\n'.format((
      print('No Pokemon to make active.\n')
  #list available pokemon
  def listpokemon(self):
    print('{} has collected the following Pokemon:\n'.format(
    for i in range(len(self.pokemons)):
      print('{}: {}'.format(i + 1, (self.pokemons[i]).name))

  #function to change the current active Pokemon
  def make_active(self, activate):
      if not (self.pokemons[activate - 1]).concious:
        print('{n} is unconcious, you can\'t activate {n}.\n'.format(n=(self.pokemons[activate -1 ]).name))
      else: = self.pokemons[activate - 1]
        print('{}\'s active Pokemon is now {}.\n'.format(, (
      print('Invalid Pokemon selected. Try listing your Pokemon.\n')

  #calculate effects of trainer using a healing potion
  def usepotion(self):
    if ( == (
      print('{} is already at max health!\n'.format(
    elif self.potions > 0:
      print('{} uses a potion to heal {} for 25 hit points!\n'.format(, (
      #call the pokemon heal method
      self.potions -= 1
      print('{} doesn\'t have enough potions to do that!\n'.format(

  def pokemonstatus(self):
    if is None:
      print('{} does not have an active Pokemon.'.format(

  #calculate effects of trainer attacking with active pokemon
  def attack(self, trainer):
    if is None:
      print('{} cannot attack without an active Pokemon!'.format(
    elif not (
      print('{} cannot attack with an unconcious Pokemon!\n'.format(
    elif not (
      print('{} automatically wins, but gains no XP as {}\'s Pokemon is unconcious.\n'.format(,
      print('{} attacks {}!\n'.format(,
      if not (
        print('{} renders {} unconcious, winning the battle and gaining 100 XP!\n'.format((, (

def autobattle (trainer1, trainer2):
  #implement effects of speed stat
  if ( > (
    gonext = True
    print('{} has the faster active Pokemon and attacks first!\n'.format(
    gonext = False
    print('{} has the faster active Pokemon and attacks first!\n'.format(
  if not (
    print('Cannot auto-battle, {}\'s Pokemon is unconcious.'.format(
  if not (
    print('Cannot auto-battle, {}\'s Pokemon is unconcious.'.format(
  while ( and (
    if gonext:
      gonext = False
      gonext = True

#test data

bob_pickachu = Pokemon('Pickachu', 3, 'Fire', 100, 0, False, 2, 2, 2)
bob_charmander = Pokemon('Charmander', 5, 'Water', 100, 50, True, 1, 2, 3)
bob_grassgalor = Pokemon('Grassgalor', 8, 'Grass', 100, 24, True, 3, 1, 2)
jane_pickachu = Pokemon('Pickachu', 4, 'Fire', 100, 80, True, 2, 2, 2)
jane_charmander = Pokemon('Charmander', 3, 'Water', 100, 30, True, 1, 2, 3)
jane_grassgalor = Pokemon('Grassgalor', 5, 'Grass', 100, 50, True, 3, 1, 2)
jim_grassgalor = Pokemon('Grassgalor', 10, 'Grass', 100, 100, True, 3, 1, 2)
bobs_mons = [bob_pickachu, bob_charmander, bob_grassgalor]
janes_mons = [jane_pickachu, jane_charmander, jane_grassgalor]
jims_mons = [jane_pickachu, jane_charmander, jane_grassgalor, bob_pickachu, bob_charmander, bob_grassgalor, jim_grassgalor]
bob = Trainer('Bob', bobs_mons, 3, 1)
jane = Trainer('Jane', janes_mons, 3, 1)
jim = Trainer('Jim', jims_mons, potions=3, active=1)