Python 学习三
上一篇 /
下一篇 2012-05-21 10:49:36
/ 个人分类:Python学习
2012年5月21
好久没有更新日志了,最近没有时间学习,刚看了下python的数组使用,学习了一个小例子:
database = [
['albert', '1234'],
['dilbert', '4242'],
['smith', '7524'],
['jones', '9873']
]
username = input ('User name: ')
pin = input ('PIN code:')
if [username, pin] in database: print ("Access granted")
else: print ("wrong PIN or username")
输出如下:
>>>
User name: dilbert
PIN code:de
>>> ================================ RESTART ================================
>>>
User name: diel
PIN code:dfe
wrong PIN or username
看书上的例子是 print "wrong PIN or username",在python3.2.3上是run不起来的,python3.2.3的用法会有一些不同,之后一些总结,暂时先写这么多
收藏
举报
TAG:
if
Python
python
else语句