2014-06-11 18 views
0
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() 
+1

嗨!歡迎來到堆棧溢出!不幸的是,你沒有正確格式化代碼,所以我們不能確定它是如何縮進的。請查看常見問題了解更多詳情。也請發佈錯誤消息。 –

+0

所提供的代碼甚至不是有效的Python,並將導致'EOL while scanning string literal'!這使得關閉變得容易 - 請確保提交*有效*和*代表*測試用例。 (並且,當問題解決後,代碼中會出現[無縮進錯誤](http://ideone.com/SpGLQ3)。) – user2864740

+0

混合空格和製表符可能會導致此問題。 –

回答

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無法讀取它,您可以刪除它並添加一個「選項卡」。