环境介绍
基本《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'
报错:
[root@Python 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'
再执行成功
[root@Python python]# python database1.py
User name: albert
PIN code: 1234
Access granted