Here is my code in python 3.4 it just keeps running the loop until the system exit when the player dies this is part of an rpg game i have been making for fun
Not entire code please note if you would like to see entire code please ask only combat function shown
def combat(h, a, d, x):
global attack
global health
global defence
global xp
death = False
while death == False:
eab = random.randint(1, 10)
yab = random.randint(1, 10)
cattack = 0
cdefence = 0
cattack = attack
cdefence = defence
cattack = cattack + yab
a = a + eab
d = d - cattack
print("you strike for " + str(cattack) + " damage")
cattack = cattack - d
if cattack > 0:
h = h - cattack
if d > 0:
print("the enemy has " + str(d) + "defence left")
if h > 0:
print("the enemy has " + str(h) + "Health left")
else :
print("the enemy dies")
death == True
xp = xp + x
print("they strike back for " + str(a))
cdefence = cdefence - a
a = a - cdefence
if a > 0:
health = health - a
if cdefence > 0:
print("you have " + str(cdefence) + " defence left!")
if health > 0:
print("you have " + str(health) + " health left")
else :
sys.exit("YOU DIED A HORRIBLE DEATH")