打破我想提出一个代码来模拟一个骰子和做其他的东西,但有一个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