模拟用户登录含注册——python第8天
print('欢迎登录尚雅梦想python学习系统'.center(30)) print('******' * 8) flag = True while flag: order = input('''按'r'或者'R'进行用户注册\n按'l'或者'L'进行用户登录''') if order.upper() == 'R': flag = True while flag: username = input('请输入您要注册的用户名:') line = open('用户信息', mode='r+', encoding='utf-8') info = line.read() info = info.split('\n') dic_info = {} for index, item in enumerate(info): if index % 2 == 0: dic_info[item] = info[index + 1] line.close() if username not in dic_info.keys(): password = input('请输入您的密码:') line = open('用户信息', mode='r+', encoding='utf-8') line.read() line.write('{}\n{}\n'.format(username, password)) line.close() break else: print('您输入的用户名已存在') continue if order.upper() == 'L': count = 3 while count > 0: line = open('用户信息', mode='r+', encoding='utf-8') info = line.read() info = info.split('\n') dic_info = {} for index, item in enumerate(info): if index % 2 == 0: dic_info[item] = info[index + 1] line.close() ID = input('请输入您的用户名:') if ID in dic_info.keys(): psw = input('请输入您的密码:') if psw == dic_info[ID]: print('登录成功,请稍后...\n欢迎{}进入python学习系统'.format(ID)) flag = False break else: count -= 1 if count == 0: print('密码错误三次,正在退出...') flag = False break print('您的密码错误,您还有{}次机会请重新输入:'.format(count)) else: count -= 1 if count == 0: print('用户名输入错误三次,正在退出...') flag = False break print('您的用户名输入错误,您还有{}次机会请重新输入:'.format(count))
模拟用户登录升级版,包括用户注册信息保存,以及登录时调取匹配

浙公网安备 33010602011771号