繁体   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