python序列成员资格

可以用做登录操作,判断用户名密码是否正确!

代码示例:

database = [
    ['albert','1234'],
    ['dilbert','4242'],
    ['smith','7524'],
    ['jones','9843']
]
username = input("UserName: ")
pin = input("PIN Code: ")
if [username,pin] in database:
    print("Access granted")
else:
    print("Access Refused")
    exit()

输出:

UserName: albert
PIN Code: 1234
Access granted

Process finished with exit code 0

 

UserName: albert
PIN Code: 2345
Access Refused

Process finished with exit code 0

 

posted @ 2017-05-23 17:16  LinuxPark  阅读(687)  评论(0编辑  收藏  举报