I'm trying to develop a program, however I seem to be repeatedly greeted by the error
TypeError: unorderable types: list() <= int()
This happens when I'm executing 2 if
loops within each other. To give a bit of backstory into the problem, I am trying to make my program determine which difficulty a user has selected, and based on this, cause the program to measure a different amount of words within a file that the user has selected prior to this point.
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 is a global variable. You assign it to the result of the split() which is a list which you then compare to a number 10 later. Essentially, you're comparing an int with a list. You should be careful on your variable names.. I would be confused by your naming conventions since there's several variables named similarly.
....
with open(FileSelection, 'r') as file:
for line in file:
WordCount = line.split()
print(WordCount)
def GameStage03_E():
if WordCount <= 10:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.