简体   繁体   English

if和elif在python 2.7上

[英]if and elif on python 2.7

I've been having some trouble debugging this code I've done for homework. 我在调试为家庭作业完成的代码时遇到了一些麻烦。 It follows the example code perfectly (as far as I can see) but it comes up with syntax error when I answer "Legend of Zelda: Ocarina of Time" and the "Unexpected EOF while parsing message when I answer GTA V. 它完全遵循了示例代码(据我所知),但是当我回答“塞尔达传说:时之笛”时,出现语法错误,而当我回答GTA V时,在解析消息时出现了意外的EOF。

game = input("What is the best game ever made?: ")

if game == "Legend of Zelda: Ocarina of Time":
    print ("Top rated")
elif game == "GTA V":
    print ("YES!")
else:
    print ("That doesn't compare to GTA V of Ocarina of Time")
game = input("What is the best game ever made?: ")

should be 应该

game = raw_input("What is the best game ever made?: ")

You probably got the example code from a Python 3 tutorial. 您可能从Python 3教程中获得了示例代码。 In Python 2, input was called raw_input and input was a pretty much useless function that did something else. 在Python 2中, input称为raw_inputinput则是一个几乎无用的函数,它做了其他事情。

Also, if you can, at this point use python 3. 另外,如果可以的话,请在此时使用python 3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM