Hello! The problem is in
hp = hp - diceValue
. What does happen? First, Python gets the right side of the equation, calculate it and then it's assigned to the left side. But hp
variable is not defined. It actually is but as a global variable. Into a function all variables are local ones. If you want to use a global variable you have to tell that to Python explicitly.hp = 10 def attack(): global hp # here you tell Python that you want to use a global variable diceValue = random.randint(1, 10) hp = hp - diceValue