我正在尝试循环战斗菜单。虽然它还没有完成,但我在循环它时遇到了问题。我希望菜单一直循环到 myhp 或 hp 低于 0。所以我使用了“while myhp > 0 or hp > 0:”
它不起作用,我做错了什么?
def fightmode(name, hp, dmg, gold):
print '\n\n\nYou are in a fight with %s' %name
print '%s has %sHP' %(name, hp)
while myhp > 0 or hp > 0:
hp = hp - mydmg
print '\n\t1. Attack \n\t2. Guard \n\t3. Run away.'
opt1= ''
allowed = ["1", "2", "3"]
while opt1 not in allowed:
opt1 = raw_input("\nWhat will you do? ")
if opt1 == "1":
print "You have inflicted %d damage on %s. %s's HP is %s" %(mydmg, name, name, hp)
if myhp > 0 :
print"myhp"
if hp > 0 :
print"theirhp"