python - python的循环问题

标签 python loops while-loop

<分区>

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

最佳答案

没关系,我想我明白了。我将“或”更改为“和”,它似乎在起作用。 这是正确的方法吗?

关于python - python的循环问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12594862/

相关文章:

python - 在使用 python while 循环和字典时遇到问题

python - Seaborn FacetGrid PointPlot 标签数据点

python - 将列表名称列表(str)转换为python中的列表列表

python-3.x - 有没有一种简单的方法可以循环迭代枚举?

java - 为什么一个空的 Java 程序会消耗内存?

python - 从 while 循环到 ValueError

python - 在列表中移动项目?

python - Django Admin 使用 nginx 端口 443 挂起

python - 在循环中调用 extract 时跳过的元素

java - 如何在java中打印这个图案?