Skip to main content
 首页 » 编程设计

python之python的循环问题

2025年05月04日12pander-it

<分区>

我正在尝试循环播放战斗菜单。虽然还没有完成,但我在循环播放时遇到了问题。我希望菜单一直循环直到 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"