我是Python的新手并正在上课。以下是我的代码。我的问题在最后一行,我希望如果有人只是按下回车键,它将被视为输入了除(1/2/3或4)之外的其他内容,这将基本上回复最后一个elif并重新开始提问。但目前它给我的输出是:
SyntaxError: unexpected EOF while parsing.
有人可以帮忙吗?
def menu_loop():
ans = True
while ans:
print("""
1. My freedom awaits me, give me my blade!
2. I've never fought before, might you help me?
3. I have already forsaken freedom, I will fight till the death.
4. Fighting is for the wicked. I refuse to fight.
Press enter to quit
""")
ans= input("What would you like to do now?")
if ans == 1:
main_loop()
break
elif ans == 2:
instructions_loop()
break
elif ans == 3:
gauntlet_loop()
break
elif ans == 4:
print("\nMen... come relieve this man of his life.")
time.sleep(2)
end_game_loop()
break
elif ans == '':
print("\nDo you not speak Latin, slave?")
谢谢,我通过Christian找到了答案。我猜我从获得指令的网站上获得的是Python 3,但我使用的是Python 2(这是为大学作业而准备的)。现在它已经可以工作了,非常感谢!