報錯內容 IndentationError: unindent does not match any outer indentation level
環境介紹
基本《Python 基礎教程(第2版 修訂版)》 作者:[挪] Magnus Lie Hetland 司維 曾軍崴 譚穎華 譯
操作系統:CentOS release 6.9 (Final)
python版本:Python 2.6.6
程序編輯器:VIM - VI IMproved 7.4
報錯內容 IndentationError: unindent does not match any outer indentation level
代碼:
#!/usr/bin/env python
database = [
[‘albert‘,‘1234‘],
[‘dilbert‘,‘4242‘],
[‘smith‘,‘7524‘],
[‘jones‘,‘9843‘]
]
username = raw_input(‘User name: ‘)
pin = raw_input(‘PIN code: ‘)
if [username,pin] in database:
print ‘Access granted‘
else:
print ‘Hello,stranger‘
報錯:
[[email protected] python]# python database1.py
File "database1.py", line 13
else:
^
IndentationError: unindent does not match any outer indentation level
問題排查:
報錯提示,沒有對齊,對比分析後else 要跟if 進行左對齊
對齊後,報錯問題解決。
代碼:
#!/usr/bin/env python
database = [
[‘albert‘,‘1234‘],
[‘dilbert‘,‘4242‘],
[‘smith‘,‘7524‘],
[‘jones‘,‘9843‘]
]
username = raw_input(‘User name: ‘)
pin = raw_input(‘PIN code: ‘)
if [username,pin] in database:
print ‘Access granted‘
else:
print ‘Hello,stranger‘
再執行成功
[[email protected] python]# python database1.py
User name: albert
PIN code: 1234
Access granted
本文出自 “大明地盤” 博客,請務必保留此出處http://damingzone.blog.51cto.com/3892167/1953787
報錯內容 IndentationError: unindent does not match any outer indentation level