簡體   English   中英

語法和縮進錯誤的問題

[英]Problems with Syntax and indentation errors

我正在閱讀一本書,這本書中的這一點要求我制作一個小型視頻游戲,該游戲調用函數,使用ifwhile到目前為止,基本上是本書所涵蓋的所有內容。 但是,我在代碼的這一部分中遇到了此錯誤:

代碼已編輯,出現新錯誤。

  File "ex35_study.py", line 24 third_scenario_code() IndentationError: unindent does not match any outer indentation level 

這是我的代碼:

     options_thirdscenario_actions = ['Examine the door', 'Try to force it']

def third_scenario_code():
    print "Let me try to crack this thing up, says Lars as he starts to type in the panel. You hear the sounds of the fight out there, there's not much time left. "
    print "After receiving several commands a window with a code pop ups. "
    print codefile.read() 


def third_scenario():
    print "You two get out of the cell and approach to the exit, a long corridor is ahead of you, flashing red lights indicate an state of emergency, you must evacuate."
    print "As soon as you two approach to the door, it closes"
    print "Crap it must be the emergency system, we have been detected"
    next = raw_input("What do you do> ")
if next == 'Examine the door':
    print "A small panel comes out, requires to enter a code of words"
    third_scenario_code()
elif next == 'Try to force it':
    print "You try to force the door with no result"
    print options_thirdscenario_actions    
    next2 = raw_input("What else do you do> " )
    if next2 = 'Examine the door'
        third_scenario_code()
else:
    print "You already did that"

我在整個程序上遇到了類似的錯誤,我懷疑它與縮進有關,但是我嘗試了在google中看到的每條建議,但都沒有取得豐碩的結果。 提前致謝。

if條件之一之后,您缺少冒號,並且需要將具有相同作用域的內容對齊,即在函數調用之后進行打印,但是您可能還會混用空格和制表符。 建議始終使用4個空格而不是制表符,並且可以為此設置大多數編程編輯器。

我還建議您掌握並使用pylint 這將幫助您發現很多潛在的錯誤,並幫助您養成良好的習慣。

由於third_scenario_code()的縮進,您需要在print下編寫它。

更改以下內容:

if next == 'Examine the door':
            print "A small panel comes out, requires to enter a code of words"
                third_scenario_code()

至 :

if next == 'Examine the door':
            print "A small panel comes out, requires to enter a code of words"
            third_scenario_code()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM