码迷,mamicode.com
首页 > 其他好文 > 详细

字典-小练习

时间:2018-04-11 11:44:14      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:小练习   strip   span   练习   username   存在   items   info   ems   

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("成功!")
        

 

字典-小练习

标签:小练习   strip   span   练习   username   存在   items   info   ems   

原文地址:https://www.cnblogs.com/ymany/p/8794380.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!