Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.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)_Python_Python 3.x - Fatal编程技术网

缩进中制表符和空格的使用不一致???(python)

缩进中制表符和空格的使用不一致???(python),python,python-3.x,Python,Python 3.x,我正在尝试制作一个石头、布、剪刀的游戏,尽管我的代码很好,但缩进错误中标签和空格的不一致使用还是出现了。 我该如何解决这个问题 我已经用notepad++、Visual Studio和默认的python IDLE重新编写了代码 任何帮助都将不胜感激。对于同一级别的if/elif/else语句,您的选项卡应该保持一致。我猜您可能希望将代码重新格式化为以下格式: if ai == 1 and rock == True: lblr = tkinter.Label(menuwol, text

我正在尝试制作一个石头、布、剪刀的游戏,尽管我的代码很好,但缩进错误中标签和空格的不一致使用还是出现了。 我该如何解决这个问题

我已经用notepad++、Visual Studio和默认的python IDLE重新编写了代码


任何帮助都将不胜感激。

对于同一级别的if/elif/else语句,您的选项卡应该保持一致。我猜您可能希望将代码重新格式化为以下格式:

if ai == 1 and rock == True:

     lblr = tkinter.Label(menuwol, text="Neither win, the both of you picked rocks.")
     time.sleep(1)
     menuwol.destroy()
     lblr.pack()

elif ai == 1 and paper == True:

    lblr = tkinter.Label(menuwol, text="Computer picked rock, you picked paper, you win!")
    time.sleep(1)
    menuwol.destroy()
    lblr.pack()

elif ai == 1 and sissors == True:

    lblr = tkinter.Label(menuwol, text="Computer picked rock, you picked sissors, computer wins!")
    time.sleep(1)
    menuwol.destroy()
    lblr.pack()

elif ai == 2 and rock == True:

    lblr = tkinter.Label(menuwol, text="Computer picked paper, you picked rock, computer wins!")
    time.sleep(1)
    menuwol.destroy()
    lblr.pack()

elif ai == 2 and paper == True:

    lblr = tkinter.Label(menuwol, text="Neither win, both of you picked paper.")
    time.sleep(1)
    menuwol.destroy()
    lblr.pack()

elif ai == 2 and sissors == True:

    lblr = tkinter.Label(menuwol, text="Computer picked paper, you picked sissors, you win!")
    time.sleep(1)
    menuwol.destroy()
    lblr.pack()

elif ai == 3 and rock == True:

    lblr = tkinter.Label(menuwol, text="Computer picked sissors, you picked rock, you win!")
    time.sleep(1)
    menuwol.destroy()
    lblr.pack()

elif ai == 3 and paper == True:

    lblr = tkinter.Label(menuwol, text="Computer picked sissors, you picked paper, computer wins!")
    time.sleep(1)
    menuwol.destroy()
    lblr.pack()

elif ai == 3 and sissors == True:

    lblr = tkinter.Label(menuwol, text="Neither win, both of you picked sissors.")
    time.sleep(1)
    menuwol.destroy()
    lblr.pack()

else:

    lblr = tkinter.Label(menuwol, text="Error BOIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII!!!")
    time.sleep(1)
    menuwol.destroy()
    lblr.pack()

如果这是您的代码,它不好,则
elif
s应与第一个
if
您的代码不好对齐,至少不像这里显示的那样。错误非常明显:缩进中有空格和制表符;用另一个替换所有代码,并修复编辑器以一致地使用空格(推荐)。“我的代码可能不正确吗?”对于任何版本的Python,该代码的缩进都不正确,但我认为在这里复制代码只是一个意外。出现这个错误消息是因为缩进Python3代码时不能混合制表符和空格,就这么简单。
if ai == 1 and rock == True:
    lblr = tkinter.Label(menuwol, text="Neither win, the both of you picked rocks.")
    time.sleep(1)
    menuwol.destroy()

elif ai == 1 and paper == True:

    lblr = tkinter.Label(menuwol, text="Computer picked rocks, you picked paper, you win!")
    time.sleep(1)
    menuwol.destroy()

elif ai == 1 and sissors == True:

    lblr = tkinter.Label(menuwol, text="Computer picked rocks, you picked sissors, computer wins!")
    time.sleep(1)
    menuwol.destroy()

elif ai == 2 and rock == True:

    lblr = tkinter.Label(menuwol, text="Computer picked paper, you picked rocks, computer wins!")
    time.sleep(1)
    menuwol.destroy()
    #rest of code