我在Python代碼中的「Syntax Error:invalid syntax」消息中遇到問題,這些代碼一直在將目標帖子移到我身上。在python 2.7中使用if語句的語法錯誤
這裏的示例代碼:
another_answer = int(raw_input("> ")
if another_answer == 1:
print "The pirate's body slowly goes limp and he whispers to you......."
print "Good luck my son. You might need this."
get_gold()
print: "Do you want to continue to the next room?"
當我在shell我得到下面這條命令:
File "ex36.py", line 179
if another_answer == 1:
^
SyntaxError: invalid syntax
我發現這個奇怪的,除去冒號後我得到一個錯誤信息在下一行:
File "ex36.py", line 180
print "The pirate's body slowly goes limp and he slowly whispers to you......."
^
SyntaxError: invalid syntax
我在上面找到的stackoverflow中心的類似問題間距和縮進,但我已經看過,一切似乎都很好。
那麼,這裏有一個縮進錯誤; 'if'語句必須與'another_answer ='語句具有相同的縮進級別。但是還有_another_語法錯誤導致您無法看到該錯誤。 – abarnert 2014-09-21 03:08:36