循環問題,我試圖環戰鬥菜單。雖然這還不算完呢,我在它的循環問題。我想菜單保持循環,直到myhp,或hp低於0.所以我用「while myhp> 0或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"
解釋什麼是「不工作」的意思。你想要做什麼,它做什麼呢? – BrenBarn
請重新格式化您的代碼,以便將其顯示爲有效的Python。不要使用標籤,而要使用四個空格進行縮進。 – 2012-09-26 06:19:49