我正在尝试开发程序,但是错误似乎让我反复受到欢迎
TypeError: unorderable types: list() <= int()
当我彼此之间执行2个
if
循环时,会发生这种情况。为了给问题提供一些背景知识,我试图使我的程序确定用户选择的困难程度,并基于此,使程序测量用户选择之前在文件中选择的单词数量。这点。Pastebin:http://pastebin.com/RZ5uKrfx
def WordCount(FileSelection):
WrdCount = 0
for line in ReadFile:
Words = line.split()
WrdCount = WrdCount + lens(Words)
return WrdCount
def E_Mode():
GameInitiationButton.config(state=NORMAL)
global DifficultyState
DifficultyState = "Easy"
def H_Mode():
GameInitiationButton.config(state=NORMAL)
global DifficultyState
DifficultyState = "Hard"
def GameStage01():
global GameStage01Button
HardModeButton.destroy()
EasyModeButton.destroy()
GameInitiationButton.destroy()
SelectTextLabel.destroy()
SelectButton = Button(root, text='Select File', bg="grey1", fg="snow", font="consolas 9",
command=GameStage02, height=1, width=30)
SelectButton.place(relx=0.5, rely=0.7, anchor='c')
GameStage01Button = Button(root, text='Initiate Game!', bg="grey1", fg="snow", font="consolas 9",
command=GameStage_E_H, state=DISABLED, height=1, width=30)
GameStage01Button.place(relx=0.5, rely=0.85, anchor='c')
def GameStage02():
global ReadFile
global WordCount
FileSelection = filedialog.askopenfilename(filetypes=(("*.txt files", ".txt"), ("*.txt files", "")))
SelectTextLabel.destroy()
with open(FileSelection, 'r') as file:
for line in file:
WordCount = line.split()
print(WordCount)
GameStage01Button.config(state=NORMAL)
# GameStage03_E()
def GameStage_E_H():
if DifficultyState == "Easy":
GameStage03_E()
elif DifficultyState == "Hard":
GameStage03_H()
def GameStage03_E():
if WordCount <= 10:
tkinter.messagebox.showinfo("ERROR", " Insufficient Amount Of Words Within Your Text File! ")
最佳答案
WordCount是一个全局变量。您将其分配给split()的结果,该结果是一个列表,之后与10进行比较。本质上,您正在将一个int与一个列表进行比较。您应该谨慎对待变量名。由于您有多个命名类似的变量,因此我对您的命名约定感到困惑。
....
with open(FileSelection, 'r') as file:
for line in file:
WordCount = line.split()
print(WordCount)
def GameStage03_E():
if WordCount <= 10:
关于python - Python错误 “TypeError: unorderable types: list() <= int()”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34561397/