代码看起来正确时,“ else”上出现意外的语法错误

时间:2018-09-04 21:37:53

标签: python-2.7 if-statement

def restudy():
    print "OK, since you decided to restudy at MIANYANG high school, you must work hard!"
    print '''
    Now, it's time to determine your destiny.
    Please answer the questions below:
    what's the result of 1+1? 
    if you give the right answer, you can go to Shanghai; but if you can't
    you'll be caught in here forever.
    '''

    test = raw_input("> ")

    if test == "2":
        print "you succeed!"
        shanghai()
    else: # that's the error line
        restudy()

这就是终端向我显示的结果:

 else:
        ^
 SyntaxError: invalid syntax

我的代码有什么问题?因为我认为这似乎是正确的。 希望有人可以帮助我。 谢谢!

0 个答案:

没有答案