Im新的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?")
謝謝你,我找到了答案感謝基督徒。我猜我從Python 3得到的指示,我在2(這是一個大學作業)。它現在正在工作,非常感謝!
謝謝你,這個幫了不少忙。我將輸入改爲raw_input,因爲我的確在使用python 2(.7)。當我添加int部分時,事情發生了,所以我只是把數字放在引號內,現在一切都很順利。非常感謝:D – GOAT
是的,你也可以做到這一點,我很高興我可以幫助你:)與你的其他項目祝你好運! – Serial