1
我试着制作一个简单的骰子滚动程序,我可以让骰子'滚动',但我无法阻止它,它只会保持,如果你输入任何东西。我试图添加它,所以如果你说'不'或'n'返回并像往常一样去我的其他功能。我说回来是因为继续我的其他代码很重要。谢谢。循环不退出,如果roll_more =='no'
import random
min = 1
def rolling6():
roll_more = "yes"
while roll_more == "yes" or roll_more =="y":
max = 6
print("Rolling the dices...")
print("The values are...")
print(random.randint(min, max))
print(random.randint(min, max))
roll = input("Roll the die again? ")
if roll_more == "no" or roll_more == "n":
return
#roll_again = "yes"
#while roll_again == "yes" or roll_again =="y":
# print("Rolling the dices...")
# print("The values are...")
# print(random.randint(min, 6))
# print(random.randint(min, 6))
# roll_again = input("Roll the die again? ")
#if roll_again == "no" or roll_again == "n":
# return
x = input("Use six sided die? ")
while x == "yes" or x =="y":
rolling6()
用户输入分配给变量'roll'并且您正在检查'roll_more'。请注意,检查也可以像''如果roll_more.lower()in ['yes','y']完成:'以节省空间并确保使用小写字母。您的代码会将“否”的值理解为“是”。 –