python2.7上的if和elif

2024-09-28 05:27:07 发布

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

我在调试这段为家庭作业编写的代码时遇到了一些问题。它完美地遵循了示例代码(据我所知),但是当我回答“塞尔达传奇:时间的陶笛”和“当我回答gtav解析消息时意外的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")

Tags: of代码game消息示例time时间传奇
1条回答
网友
1楼 · 发布于 2024-09-28 05:27:07
game = input("What is the best game ever made?: ")

应该是

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

您可能从python3教程中获得了示例代码。在python2中,input被称为raw_inputinput是一个非常无用的函数,它做了其他的事情。你知道吗

另外,如果可以的话,现在可以使用python3。你知道吗

相关问题 更多 >

    热门问题