尝试创建一个程序,打印4个骰子掷骰子如果总和大于8然后小于20.当我运行这个我得到一个无限循环。我尝试设置total = 0,然后将4个骰子的总和加到while循环中,但是没有奏效。骰子滚动python
代码:
from random import randint
def main():
total = sum(diRoll())
while total > 8 and total < 20:
print(diRoll())
def diRoll():
dice1 = randint(1, 6)
dice2 = randint(1, 6)
dice3 = randint(1, 6)
dice4 = randint(1, 6)
diceRolls = dice1, dice2, dice3, dice4
return sorted(diceRolls)
main()
我已经推出的问题回来,提供匹配的答案的人。如果您感觉需要,您可以添加解决方案作为答案。 – Blair 2014-10-30 02:09:32