【问题标题】:"Unindent does not match any outer indentation level" in PythonPython中的“Unndent不匹配任何外部缩进级别”
【发布时间】:2015-08-07 02:57:48
【问题描述】:

我有一些 Python 代码无法运行。错误消息说:

unindent 不匹配任何外部缩进级别

def main1():       

        password = "LPPJJAS"
        user_input = raw_input('Please Enter Password: ')

        if user_input == password:
                print 'All distances have been split so one pixel is equal to two centimetres'
               time.sleep(1)


        elif user_input != password:
                print 'Incorrect Password, terminating... \n'
                exit("pow")

if __name__ == "__main__":
        main1()`

【问题讨论】:

  • 错误消息应该会提示您在哪里,但对我来说它看起来像print 'All distances...'之前的额外空格

标签: python indentation


【解决方案1】:

第 5 行之前有一个额外的空格 - print 'All distances...。 Python 期望每一行都有相同的缩进。 (通常是 4 个空格。)

password = "LPPJJAS"
user_input = raw_input('Please Enter Password: ')

if user_input == password:
    print 'All distances have been split so one pixel is equal to two centimetres'
    time.sleep(1)

elif user_input != password:
    print 'Incorrect Password, terminating... \n'
    exit("pow")

【讨论】:

  • 显然,错误出现在time.sleep(1)之后,因为外部缩进不匹配。
猜你喜欢
  • 1970-01-01
  • 2012-07-04
  • 2019-06-28
  • 2018-02-08
  • 1970-01-01
  • 1970-01-01
  • 2010-12-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多