""" The error you're seeing is likely because you're trying to reference variables (plHP and enHP) before they are defined. Also, the condition while plHP or enHP >= 0 is not doing what you intend it to do. It should be checking both plHP and enHP individually. """ """ I've combined the global declarations for variables in the same block for better readability. I've called the Orc() and player() functions to initialize the variables before entering the while loop. I've corrected the condition in the while loop to check both player and enemy HP individually. The loop continues as long as both plHP and enHP are greater than zero. """ import random def Orc(): global enName, enAtt, enHP, enDef, enMove, enExp enName = "Orc" enAtt = 0 enDef = 13 enMove = random.randint(0, 13) enExp = 100 enHP = 100 def player(): global plName, plAtt, plDef, plHP plName = input("What is your name?") plAtt = 10 plDef = 13 plHP = 50 Orc() # Initialize enemy Orc player() # Initialize player while plHP > 0 and enHP > 0: # Check both player and enemy HP enHP -= plAtt print(plName, "has attacked", enName, "for", plAtt)