I'm having trouble with an if statement inside a while loop.
while pressed == 8 :
print(answerlistx[randomimage], answerlisty[randomimage])
entryx = e1.get()
entryy = e2.get()
answerx = answerlistx[randomimage]
answery = answerlisty[randomimage]
print(entryx, entryy)
if e1 == answerx and e2 == answery:
print("correct")
canvas.delete(images)
randomimage = random.randrange(0,49+1)
scorecounter = scorecounter + 1
game = PhotoImage(file=imagelist[randomimage])
images = canvas.create_image(30, 65, image = game, anchor = NW)
e1.delete(0, END)
e2.delete(0, END)
pressed = ''
else:
print("incorrect")
e1.delete(0, END)
e2.delete(0, END)
pressed = ''
The while loop is supposed to check to see if the inputs from the entry widget match the the answer but even when the answer is correct it goes to the else statement. I have 2 print statements just before the if statement which prints the input and what the answer is just incase it didn't have that but it does display it both correctly. I also thought it might have been a mix up with strings and integers so I changed all the answers in the answerlist to strings with no luck. Anyone able to figure out what is wrong with it? Thanks in advance.
else,e1 == answerx and e2 == answeryis not true. PERIOD. now, figure out why. Have you checked what the type and value of those variables? some trace messages can do miracles...entryxandentryywithanswerxandanswery? as this is what you are printing before the comparison. Currently you are comparinge1ande2which you are not printing for visual validation.