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()
我正在尝试制作摇滚,纸张,剪刀游戏,并且即使我的代码很好,缩进中的标签和空格的不一致使用错误也会出现。 我该如何解决这个问题?
我在notepad ++,Visual Studios和默认的python IDLE中重写了代码。
非常感谢任何帮助。
答案 0 :(得分:0)
对于同一级别的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()
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