Working on pokemon game, no console output

Hiya,

First time posting here, so I hope I’m posting in the right place. I’m working on the pokemon project:
Pokemon project

I’ve run into a snag. I’ve created a pokemon class. At least I think I have, but when I test it I don’t get the expected console output. I don’t get an error either, so I think my syntax is correct but my logic is nonsense. Can anyone help me in the right direction?

class pokemon:
    def __init__(self, name, level, elemental_type, max_health, health, is_knocked_out):
        self.name = name
        self.level = level
        self.elemental_type = elemental_type
        self.max_health = max_health
        self.health = health
        self.is_knocked_out = is_knocked_out

    def lose_health(self, health, damage):
        return self.health - damage
        print("{} now has {} health left!".format(self.name, self.health))

    def gain_health(self, healing):
        return self.health + healing
        print("{} now has {} health!".format(self.name, self.health))

    def knock_out(self, health):
        if health == 0:
            is_knocked_out = True
            return is_knocked_out
        print("{} is knocked out.".format(self.name))

    def attack(self, other_pokemon):
        other_pokemon.lose_health(level)

class trainer:
    def __init__(self, name, pokemons, active_pokemon, potions):
        self.name = name
        self.pokemons = pokemons
        self.active_pokemon = active_pokemon
        self.potions = potions



charm = pokemon("Charm",2,"fire",10,10,False)
charm.gain_health(10)

thanks in advance
Best regards,

Jacob

Hi there!

I presume, when you say you’re not getting the expected output, that you’re confused as to why you’re not seeing "Charm now has 20 health!" on the console when you call charm.gain_health(10).

It’s all down to your function definition:

    def gain_health(self, healing):
        return self.health + healing
        print("{} now has {} health!".format(self.name, self.health))

return has a specific purpose in a function, which you ought to know if you’ve reached the point of working on classes and the Pokémon project.

Do you think that the print call on the following row will ever be reached? :slight_smile:

Hi there,
I apologize for the late reply. I had been battling this for about 2 days when I caved in and asked the question. I figured it out about 30 minutes after posting the question! :roll_eyes:

I want to thank you for taking your time to reply. Even though I managed to figure it out myself, it still means a lot. :slight_smile:

1 Like

No need to apologise for getting stuck into coding or figuring it out on your own!

If there’s anything else that you get stuck on, pop back and ask. :smiley:

1 Like