打破我想提出一個代碼來模擬一個骰子和做其他的東西,但有一個while循環未被打破,我不知道爲什麼。While循環不是在邏輯的情況下
import random
import math
#infinite loop
while True:
while True:
a = 0
#input amount of dice
att_die = raw_input('Attacking dice: ')
def_die = raw_input('Defending dice: ')
#att
#if NaN
if str(att_die).isdigit() == False:
print('NaN')
#if not NaN
else:
a += 1
#def
#if NaN
if str(def_die).isdigit() == False:
print('NaN')
#if not NaN
else:
a +=1
if a == 2:
break
if att_die >= def_die:
no = def_die
else:
no = att_die
print (no)
x = 0
while x <= no:
att_loss = 0
def_loss = 0
roll_att = random.randint(1,6)
roll_def = random.randint(1,6)
if roll_att <= roll_def:
att_loss += 1
elif roll_att == roll_def:
att_loss += 1
else:
def_loss += 1
x += 1
print(x)
print('Att: -' + str(att_loss) + '\nDef: -' + str(def_loss))
一切工作,直到最後while循環,它只是不斷輸出x的值增加。 如何解決這個問題的任何幫助,將不勝感激。 在此先感謝
另外,我運行2.7.6。我不知道這是否重要 –
在您的打印聲明中添加'no'並顯示輸出 – mackworth