Python if语句在while循环中没有响应

2024-04-25 05:16:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我在while循环中遇到if语句问题。

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 = ''

while循环应该检查entry小部件的输入是否与答案匹配,但即使答案正确,它也会转到else语句。我在if语句之前有两个print语句,用于打印输入和答案,以防没有,但它确实正确地显示了这两个值。我还认为这可能是字符串和整数的混合,所以我把答案列表中的所有答案都改成了字符串,运气不好。 有谁能弄清楚这是怎么回事吗? 提前谢谢。


Tags: 答案getif语句deleteendprintwhile