开发者

Syntax error with IF statement in Python 3.0

I am teaching myself some Python and I have come across a problem which is probably plainly obvious, except that I can't see it and I need another pair of eyes.

I am making a small game I made into a gui program. I have this section of code, which when run gives me "Traceback (most r开发者_StackOverflow社区ecent call last): File "", line 21, in Syntax Error: if playguess == "A":: , line 2124" Line 21 being if playguess == "A":

There may be a couple unrelated things wrong, but it's the IF statement that is baffling me right now. I have imported the Tkinter module, I just copied the part that I thought was relevant.

def compare():
    R = Label(main, text = 'Yes you are right !')
    W = Label(main, text = "No, It's "+str(states[state])
    #if playerguess == str(states[state]):
    if playguess == "A":
       R.pack()
    else:
       W.pack()

#print ("Guess State Capitols")
state = choosestate()
main = Tk()
main.title("Guess State Capitols")
main.geometry('450x100+200+100')

Q = Label(main,text = 'What is the capitol of ' +state)
Q.pack()
playerguess = Entry(main)
playerguess.pack()
playguess = playerguess.get()



main.mainloop()


The line:

W = Label(main, text = "No, It's "+str(states[state])

Doesn't have a closing parentheses for the Label() class/function.

Therefore, the if statement is interpreted as being inside parentheses, which doesn't work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜