用户注册及验证写法

用户注册,将用户账号密码以字典形式存入列表.输入n结束

users_list[{'name':'user','password':'pwd'}]

users_list = []
massage = '....用户注册....'
print(massage)
while True:
user = input('请输入用户名:')
if user == 'n':
break
pwd = input('请输入用户密码:')
users_list_info = {'name':user,'password':pwd} #将用户信息直接赋值到字典
users_list.append(users_list_info) #将字典做为元素追加到列表中.
print(users_list)

用户登陆验证

loding = '登陆失败!'
user_name = input('请输入登陆名:')
user_pwd = input('请输入登陆密码:')
for itme in users_list:
if itme['name'] == user_name and itme['password'] == user_pwd: #循环对比
loding = '登陆成功!' #解决打印全错的一种方式.
print(loding)

posted @ 2019-06-09 20:43  新手村的老鸟  阅读(471)  评论(0编辑  收藏  举报