我已经从这个页面输入了代码PythonForBeginners 但如果我执行它,它将永远持续下去,而不会问我是否要再次掷骰子。我错过什么了吗?这样行吗?在
import random
min = 1
max = 6
roll_again = "yes"
while roll_again == "yes" or roll_again == "y":
print "Rolling the dices..."
print "The values are...."
print random.randint(min, max)
print random.randint(min, max)
roll_again = raw_input("Roll the dices again?")
一种方法是使用这样的类。在
如果用户没有输入“Yes”或“Y”,我退出程序,你可以让它更聪明。在
关于while循环的一些信息-https://www.tutorialspoint.com/python/python_while_loop.htm
我刚开始做同样的问题。我对你的初始代码做了一些调整,如下所示,它奏效了。在
更高效和优雅的解决方案是:
^{pr2}$相关问题 更多 >
编程相关推荐