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