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语句

 

评分:0

我来说两句

我的栏目

日历

« 2024-04-29  
 123456
78910111213
14151617181920
21222324252627
282930    

我的存档

数据统计

  • 访问量: 2091
  • 日志数: 4
  • 建立时间: 2012-05-09
  • 更新时间: 2012-05-21

RSS订阅

Open Toolbar