我用Python编写了一个非常简单的掷骰子脚本。你可以滚三次。但是,我不知道如何打破while循环,避免最后一次的原始输入。在
#!/usr/bin/python
from random import randrange, uniform
def rollDice():
dice = randrange(3,18)
print ("You rolled: %s" % dice)
maxReRoll = 2
c = 0
reRoll = "y"
while reRoll in ["Yes", "yes", "y", "Y"]:
if c > maxReRoll:
break
else:
rollDice()
c+=1
reRoll = raw_input("Roll again? y/n ")
只是需要一点交换。在
这应该对您有用:
相关问题 更多 >
编程相关推荐