How do I print a variable within a class' if statement?
Question: I'm trying to print a variable in Python using the following code:

    
    
    from time import sleep
    import random
    
    class Hero:
        def __init__(self,name):
            self.name = name
    
            if name == "rock":
                self.health = 50
                self.attack = 10
    
            elif name == "paper":
                self.health = 70
                self.attack = 7
    
            elif name == "scissors":
                self.health = 100
                self.attack = 5
    
        def dmg(self, other):
            other.ehealth -= self.attack
    
    start = 1
    
    while start == 1:
        name = input("Pick a class [rock/paper/scissors]")
    
        if name != "rock" or "paper" or "scissors":
            print ("That player does not exist. Try again.")
            start = 1
    
        else:
            start = 1
    
        player = Hero(name)
        enemyName = ["erock", "epaper", "escissors"]
        ename = random.choice(enemyName)
    
        print ("Your character is", name, "which comes with", self.health, "health, and", self.attack, "attack.")
        print("")
    
        sleep(1)
    
        print ("Your enemy is", ename, "which comes with", ehealth, "health, and", eattack, "attack.")
    

I can't figure out a way to access and print the variable "self.health" under
the "Hero" class. I can access "name" just fine. Maybe it's the fact that it's
under an if statement? Can someone help me out?


Answer: `self` is just a parameter name used inside the methods. Don't use it outside
the method.

To access the variables refer to them using the object name (`player`) like
this

    
    
    player.health
    

The `name` variable you are printing "works" because it's not from the object.
You should use the same notation to access that too:

    
    
    player.name
    

