字典-小练习

user = {'whx':'whx','123':'123','qwe':'qwe'}

1.验证username,pssd存在于字典中

方法一:

username = input("账号:").strip()
pssd = input("密码:").strip() if username in line:
   if user[username] == pssd:   print("成功")

 方法二:

username = input("账号:").strip()
passwd = input("密码:").strip()
for info,passwd in user.items():
    if info == usename and passwd == pwd:
        print("成功!")
        

 

posted @ 2018-04-11 10:55  暮色森森  阅读(149)  评论(0编辑  收藏  举报