标签:重试 while word 帐户 sage 登陆 [] and 用户
‘‘‘
构建用户列表,格式为:
[{‘user‘: ‘k1‘, ‘value‘: ‘v1‘},
{‘user‘: ‘k2‘, ‘value‘: ‘v2‘},
{‘user‘: ‘k3‘, ‘value‘: ‘v3‘}]
Q为停止录入,然后使用用户列表中的内容登陆,失败则重新输入.
‘‘‘
lst = []
while 1:
dic = {}
a = input(‘用户名:‘)
if a.upper() == "Q":
break
b = input(‘密码:‘)
dic[‘user‘] = a
dic[‘value‘] = b
lst.append(dic)
print(lst)
while 1:
username = input(‘请输入用户名:‘)
password = input(‘请输入密码:‘)
message = ‘登录失败!请重试!‘
for i in lst:
if i[‘user‘] == username and i[‘value‘] == password:
message = ‘登陆成功!‘
print(message)
break
if message == ‘登陆成功!‘:
break
print(message)
标签:重试 while word 帐户 sage 登陆 [] and 用户
原文地址:https://www.cnblogs.com/zjx1/p/10644772.html