def cave():
global key
global response
print(''' You find yourself standing infront of a cave.
You venture into the cave to find a large door blocking
your path.
(insert key, turn around''')
response = input("Enter a command: ")
while response != 'insert key' or response != 'turn around':
if response =='insert key' or response == 'turn around':
break
print('Choose one of the options: ")
response = input()
if response == 'insert key':
if key == 1:
win()
else:
print('''You don't have a key. Get One!!''')
elif response == 'turn around' :
home()
0
A
回答
7
這幾乎是總是混合標籤和空格造成的。用一個編輯器檢查你的文件內容,這個編輯器可以告訴你這個,比如在vi
中使用:set list
。
但是你可能也想看看這個行:
print('Choose one of the options: ")
你一個報價類型開始您的字符串,並與另一個,這是有效的結局既不是Python的2 也不 3。
一旦我修好了,並確保縮進是正確的,它對我來說工作得很好。我不得不添加一個名爲cave()
的主線,但它沒有錯誤地運行,儘管沒有太大用處,因爲我沒有任何其他代碼。
0
如果您使用Notepade +或VIM,請檢查標籤和空格在哪裏。
還要確保您開始的字符串必須以相同的字符結尾。如果您以'
(單引號)開頭,則以相同結束。
print('Choose one of the options: ")
Ablove線開始與'
但"
結束。這會給你syntext錯誤。
0
當您粘貼代碼時,在代碼爲4空格之前(而不是在ascii中),python無法讀取它,您可以刪除它並添加一個「選項卡」。
相關問題
- 1. Python說:「預計一個縮進塊」
- 2. Python「預計有縮進塊」
- 3. 「預計縮進塊」的錯誤說明
- 4. Python說我沒有屬性,當我做
- 5. Python引發縮進塊錯誤。沒有看到它
- 6. 預計縮進塊 - python
- 7. Python:預期的縮進塊
- 8. 預計縮進塊在Python
- 9. Python中的縮進塊
- 10. Android SDK說我沒有JDK,不是嗎?
- 11. Python縮進當沒有縮進錯誤時出錯
- 12. 縮進錯誤沒有意義 - Python
- 13. 不同的縮進python沒有錯誤
- 14. 我不知道這個Python代碼有什麼問題,但它說「預計一個縮進塊」?
- 15. 縮進錯誤:預計縮進塊python 3.6
- 16. Python的縮進問題:預期的縮進塊
- 17. vim中的塊縮進/取消縮進python代碼
- 18. Python「預期的縮進塊」IndentationError?
- 19. Python預期了縮進塊錯誤
- 20. Python IndentationError:Xcode上的「預期縮進塊」
- 21. IndentationError:預計縮進塊[python]的
- 22. python IndentationError:預計一個縮進塊
- 23. Python的錯誤:IndentationError:預計縮進塊
- 24. 的Python + OpenGL上下文縮進塊
- 25. 預計Python遊戲中的縮進塊
- 26. 如何在Python中創建縮進塊?
- 27. 預計在Python中的縮進塊
- 28. Python - 錯誤:期望的縮進塊
- 29. 「預計縮進塊錯誤」在Python
- 30. Python的 - 預期的縮進塊
嗨!歡迎來到堆棧溢出!不幸的是,你沒有正確格式化代碼,所以我們不能確定它是如何縮進的。請查看常見問題了解更多詳情。也請發佈錯誤消息。 –
所提供的代碼甚至不是有效的Python,並將導致'EOL while scanning string literal'!這使得關閉變得容易 - 請確保提交*有效*和*代表*測試用例。 (並且,當問題解決後,代碼中會出現[無縮進錯誤](http://ideone.com/SpGLQ3)。) – user2864740
混合空格和製表符可能會導致此問題。 –