Become a Pokemon Master Challenge Project (Python)

Congratulations on completing your project!

Compare your project to our solution code and share your project below! Your solution might not look exactly like ours, and that’s okay! The most important thing right now is to get your code working as it should (you can always refactor more later). There are multiple ways to complete these projects and you should exercise your creative abilities in doing so.

This is a safe space for you to ask questions about any sample solution code and share your work with others! Simply reply to this thread to get the conversation started. Feedback is a vital component in getting better with coding and all ability levels are welcome here, so don’t be shy!

About community guidelines: This is a supportive and kind community of people learning and developing their skills. All comments here are expected to keep to our community guidelines

How do I share my own solutions?

  • If you completed the project off-platform, you can upload your project to your own GitHub and share the public link on the relevant project topic.
  • If you completed the project in the Codecademy learning environment, use the share code link at the bottom of your code editor to create a gist, and then share that link here.

Do I really need to get set up on GitHub?
Yes! Both of these sharing methods require you to get set up on GitHub, and trust us, it’s worth your time. Here’s why:

  1. Once you have your project in GitHub, you’ll be able to share proof of your work with potential employers, and link out to it on your CV.
  2. It’s a great opportunity to get your feet wet using a development tool that tech workers use on the job, every day.

Not sure how to get started? We’ve got you covered - read this article for the easiest way to get set up on GitHub.

Best practices for asking questions about the sample solution

  • Be specific! Reference exact line numbers and syntax so others are able to identify the area of the code you have questions about.
1 Like
1 Like

I utterly lost track of time to this last night. I have forced myself to stop the project here (for now) so that I can continue my courses here.

Some fun things I’ve implemented:
You can do trainer battles or fight and catch wild pokemon.
You can spend gold won from trainers at a PokeShop (buy 1, 10, or max affordable)
In battle, you can see each Trainer’s pokeballs (active vs. fainted)

Some things I would still like to do:
Add a leveling/evolution system that scales appropriately.
Implement Bill’s storage PC.
Towns and gyms.

All feedback welcome!
One question I had while making this project relates to the functions that handle wild battles and trainer battles. Both events are handles very similarly, except for a few distinctions throughout each function body. I’ll admit I started writing the second function by copying the first, which was my first indicator there may be a better way. In the spirit of having a single function handle both scenarios, I explored a contextual flag (“in wild” vs. “in trainer battle”) or using decorators. The latter does not seem to be suited to merging functions that are incongruously similar, and the former felt cluttered.
Any advice is greatly appreciated!


Check it out.

I mostly went for what the project asked for, added a rock type and ice type as well.
I created a dictionary to handle type advantages, saves me from nasty looking if conditions.
I also gave my inherited charmander a special move flamethrower.
I created another dictionary to keep evolutions. This makes them easier to track, one could keep an entire dictionary of a bunch of pokemon keeping their evolutions like that or read from a file perhaps.

I handled the different cases and if I get time to implement a battle, I have a function ready made to check if all pokemon have fainted (to check for end of the battle)
In the battle, I would need a speed attribute, determining who gets to attack first.

It was a fun project, especially because I love pokemon games!

It is quite well made. Would be interesting to make it playable.

A few weeks ago, I did a similar project:

Since it is more advanced, I publish it here, to give an idea of what can be done without a real user interface, even if not really well made.

That’s pretty cool! One way I could take my own project forward could be to introduce a move class, each move has a name, type, damage etc. Each pokemon gets moves and all.

As I mentioned before a battle is what I want to implement later first. That could be achieved in a while loop till one of the players runs out of pokemon. We can do a lot with just a command line interface, it’s fun and quite rewarding to see all those lines of code finally come together and work.

Yes, it is pretty cool, and at the end, it seems not so complicated to create some game mechanics, which is nice.
But would be nice to make it playable in a way that when you start the script, it directly asks you what you want to do, and you just have to select.

For example:

[print(f"{index + 1}: {}") for index, pokemon in enumerate(available_pokemons)]
            pokemon_choice = None
            while pokemon_choice == None:
                    pokemon_choice = int(input("Select the pokemon you want to switch to: "))
                    if pokemon_choice > len(available_pokemons) or pokemon_choice < 1:
                        print("You didn't enter a valid option.")    
                        pokemon_choice = None
                    print("You didn't enter a valid option.")
                    pokemon_choice = None
            self.active_pokemon = available_pokemons[pokemon_choice - 1]

That’s a part of my function to switch pokemon. It displays the list and the player has to choose the corresponding number. My RPG Script works that way as well.

1 Like

Yeah I get what you mean. I’ll try incorporating this some time in the future when I have a bit more time. thanks!

I have added an interactive terminal-based interface so you can fight against each other. True, it is based on the input() command, so it does not work in the terminal built into Codecademy.

Hey, it definitely works nice!
The only thins I would improve is showing the health of your enemy’s pokemon after the damage, it’s really not clear if you are winning or loosing. Otherwise pretty cool!

1 Like

Here’s my version, playable in terminal.
So far it looks like it’s bugs free.

1 Like

Thanks for an advice - I added info about health when pokemon gains/loses health.
Your version is cool! I even want to add more features to my game now. And think about web-design course - probably it would be cool to be able to make graphical browser interface for such projects.

Hey, no worries and thanks for the feedback! I’m glad you liked it.

For sure, interface would be nice as well. Personally I’ll go for web scraping first, sound really interesting to me

Super interesting project!
This is what I have so far. I am going to work out the additional functionalities in item 9 next.

Hello community,

I finally finish this nice project.
Sharing my code here:


Need help with an error.

# Create a Pokémon class.
# The __init__() method of our Pokémon class created variables to keep track of the Pokémon’s name,
# level, type (for example "Fire" or "Water"), maximum health, current health,
# and whether or not the Pokémon was knocked out.
# In our implementation, the maximum health was determined by the Pokémon’s level.

# Give your Pokémon class some functionality.
# Our Pokémon class had a variety of methods that changed the variables associated with a Pokémon.
# For example, it had a method the decreased the Pokémon’s health (we called this lose_health)
# and a method for regaining health.
# We also created a method that would officially “knock out” a Pokémon (when its health became 0)
# and another method to revive a knocked out Pokémon.
# All of these methods had print statements to let the user know what was happening.
# For example, we might print something like "Charmander now has 30 health" when healing.

# One of the trickier methods we created in the Pokémon class was the attack method.
# This method takes another Pokémon as an argument and deals damage to that Pokémon.
# The amount of damage dealt depends on the types of the attacking Pokémon and the Pokémon being attacked.
# If the attacking Pokémon has advantage over the other Pokémon (for example, a "Fire" Pokémon attacking a "Grass" Pokémon),
# we dealt damage equal to twice the attacking Pokémon’s level.
# If the attacking Pokémon was at a disadvantage (for example, a "Grass" Pokémon attacking a "Fire" Pokémon),
# we dealt damage equal to half the attacking Pokémon’s level.
# Make sure to put in appropriate print statements to let the user know what is happening when one Pokémon attacks another.

class Pokemon:
    def __init__(self, name, level, type, health_maximum, health_current, knocked_out): = name
        self.level = level
        self.type = type
        self.health_maximum = health_maximum
        self.health_current = health_current
        self.knocked_out = knocked_out

    def health_decrease(self, decrease):
        hp_lost = self.health_current - decrease
        print("{} health was lost.".format(hp_lost))
        return self.health_current - decrease

    def health_increase(self, increase):
        hp = self.health_current
        self.health_current = self.health_current + increase

        if self.health_current < self.health_maximum:
            self.health_current = self.health_maximum

        new_hp = self.health_current - hp
        print("{} health was restored.".format(new_hp))

        return self.health_current

    def health_knocked_out(self):
        if self.health_current < 0 and self.knocked_out == False:
            self.knocked_out = True
        return self.knocked_out

    def health_message(self):
        return "{name} now has {current}/{max} health.".format(, current=self.health_current, max=self.health_maximum)

    def attack(self, target):
        damage = 0

        if self.is_knocked_out:
            print("{name} can't attack because it is knocked out!".format(

        elif (self.type == "Fire" and target.type == "Water") or (self.type == "Water" and target.type == "Electric"):
            print("Half-Damage dealt.\n{attacker} attacked {victim} for {damage} damage.".format(
      ,, damage=round(self.level * 0.5)))
            damage = self.level * 0.5

        elif (self.type == "Fire" and target.type == "Ice") or (self.type == "Electric" and target.type == "Water"):
            print("Double-Damage dealt.\n{attacker} attacked {victim} for {damage} damage.".format(
      ,, damage=self.level * 2))
            damage = self.level * 2.0

            print("{attacker} attacked {victim} for {damage} damage.".format(
      ,, damage=self.level))
            damage = self.level

        return target.health_decrease(damage)

# Make a Trainer class.
# A Trainer can have up to 6 Pokémon, which we stored in a list.
# A trainer also has a name, and a number of potions they can use to heal their Pokémon.
# A trainer also has a “currently active Pokémon”, which we represented as a number.

# Give your Trainer class some functionality through methods.
# Our trainer is able to use a potion and attack another trainer.
# When a potion is used, it heals the trainer’s currently active Pokémon.
# Similarly, when a trainer attacks another trainer,
# the currently active Pokémon deals damage to the other trainer’s current Pokémon.
# Finally, the trainer is able to switch which Pokémon is currently active.

class Trainer:
    def __init__(self, pokemons, potions, name, current_pokemon):
        self.pokemons = pokemons
        self.potions = potions = name
        self.current_pokemon = current_pokemon

    def use_potion(self, pokemon):
        print("{trainer} uses potion on {target}".format(
  , target=self.current_pokemon))
        return Pokemon.health_increase(pokemon)

    def attack(self, target):
        print("{attacker} attacks {target}".format(
            attacker=self.current_pokemon, target=target))
        return Pokemon.health_decrease(target)

    def is_active(self, current_pokemon):
        print("{} is the active Pokemon.".format(current_pokemon))

dratini = Pokemon("Pikachu", "Female", 1, "Electric", 35, 5,
                  55, 30, 50, 90, 0.4, 13.2, 190, "Medium Fast", False)

charmander = Pokemon("Charmander", "Male", 2, "Fire", 39,
                     9, 52, 43, 50, 65, 0.6, 8.5, 45, "Medium Slow", False)

dewgong = Pokemon("Dewgong", "Female", 3, "Ice", 90, 9, 70,
                  80, 95, 70, 1.7, 120, 75, "Medium Fast", False)

squirtle = Pokemon("Squirtle", "Male", 4, "Water", 44, 4, 48,
                   65, 50, 43, 0.5, 9.0, 45, "Medium Slow", False)


When I test out this…


I get this error…

line 139 TypeError: ‘ini’ object is not callable.

Not sure how this happened. It previously worked before I added the Trainer class. Not sure what I changed to break this. Out of ideas how to fix this.

Just tried copy/pasting tha code into my editor and I’m getting errors from this line as there are more arguments than the Pokemon class method __init__ exptexted-

dratini = Pokemon("Pikachu", "Female", 1, "Electric", 35, 5,
                  55, 30, 50, 90, 0.4, 13.2, 190, "Medium Fast", False)

Expected 7 arguments, received 16.

Probably best to rename one of your arguments (Pokemon class) to something other than type since you’d be overriding the build-in keyword too.

1 Like