Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如果roll_more==';否';_Python_Python 3.x_Dice - Fatal编程技术网

Python 如果roll_more==';否';

Python 如果roll_more==';否';,python,python-3.x,dice,Python,Python 3.x,Dice,我试着制作一个简单的掷骰子程序,我可以让骰子“滚动”,但我无法阻止它,只有当你输入任何东西时,它才会保持。我尝试添加它,因此如果您说“否”或“n”,它将返回并像往常一样转到我的其他功能。我之所以说return,是因为继续我的其他代码很重要。多谢各位 import random min = 1 def rolling6(): roll_more = "yes" while roll_more == "yes" or roll_more =="y": max = 6

我试着制作一个简单的掷骰子程序,我可以让骰子“滚动”,但我无法阻止它,只有当你输入任何东西时,它才会保持。我尝试添加它,因此如果您说“否”或“n”,它将返回并像往常一样转到我的其他功能。我之所以说return,是因为继续我的其他代码很重要。多谢各位

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\u more
,因此您总是对照常量“yes”进行检查

此外,您的
x
roll\u more
变量不包含您期望的值。首先,输入“yes”进入循环,以便调用
rolling6
。然后,进入rolling6循环。当您通过输入“否”退出该循环时,您将退出到外部循环,读取仍然具有值“是”的
x
(因为您从未在任何地方重写它),这意味着您不会脱离该循环,并再次进入
rolling6

您可能希望将
roll
更改为
roll\u more
并将
更改为
,而x==“是”或x==“y”:
如果x==“是”或x==“y”:


另外,如果roll\u more==“no”或roll\u more==“n”,您的
返回是多余的,因为该语句后面没有代码。

用户输入被分配给变量
roll
,您正在检查
roll\u more
。请注意,检查也可以像在['yes','y']中滚动更多.lower()那样进行:
,以节省空间并确保使用小写。代码将
No
的值理解为
yes