SyntaxError: invalid syntax in def
SyntaxError: invalid syntax in def
我正在尝试 运行 以下代码:
from tkinter import *
import random
root=TK()
root.title("Password Generator")
root.geometry("640x480")
label=Label(root)
array_3D=[[['1','2','3','4','5','6'],["Head","Tail"],["A","B","C","D","E","F","G","H"]]
def new_password():
random_no_1=random.randint(0,5)
random_no_2=random.randint(0,1)
random_no_3=random.randint(0,7)
letter_1=str(array_3D[0][0][random_no_1])
letter_2=str(array_3D[0][1][random_no_2])
letter_3=str(array_3D[0][2][random_no_3])
label["text"]=letter_1+letter_2+letter_3
btn=Button(root,text="Generate 'Weak' Password",command=new_password)
btn.place(relx=0.5,rely=0.5,anchor=CENTER)
label.place(relx=0.5,rely=0.6,anchor=CENTER)
root.mainloop()
它给我以下错误:
文件“main.py”,第 9 行
def new_password():
^
语法错误:语法无效
有什么问题?
尝试更改缩进,但没有任何反应
您似乎忘记了之前列表列表中的右括号。
array_3D=[[['1','2','3','4','5','6'],["Head","Tail"],["A","B","C","D","E","F","G","H"]]
3只开2尾收。
您错过了 array_3D
的右括号
试试看
array_3D=[[['1','2','3','4','5','6'],["Head","Tail"],["A","B","C","D","E","F","G","H"]]]
我正在尝试 运行 以下代码:
from tkinter import *
import random
root=TK()
root.title("Password Generator")
root.geometry("640x480")
label=Label(root)
array_3D=[[['1','2','3','4','5','6'],["Head","Tail"],["A","B","C","D","E","F","G","H"]]
def new_password():
random_no_1=random.randint(0,5)
random_no_2=random.randint(0,1)
random_no_3=random.randint(0,7)
letter_1=str(array_3D[0][0][random_no_1])
letter_2=str(array_3D[0][1][random_no_2])
letter_3=str(array_3D[0][2][random_no_3])
label["text"]=letter_1+letter_2+letter_3
btn=Button(root,text="Generate 'Weak' Password",command=new_password)
btn.place(relx=0.5,rely=0.5,anchor=CENTER)
label.place(relx=0.5,rely=0.6,anchor=CENTER)
root.mainloop()
它给我以下错误: 文件“main.py”,第 9 行 def new_password(): ^ 语法错误:语法无效
有什么问题?
尝试更改缩进,但没有任何反应
您似乎忘记了之前列表列表中的右括号。
array_3D=[[['1','2','3','4','5','6'],["Head","Tail"],["A","B","C","D","E","F","G","H"]]
3只开2尾收。
您错过了 array_3D
试试看
array_3D=[[['1','2','3','4','5','6'],["Head","Tail"],["A","B","C","D","E","F","G","H"]]]