用户注册后,将用户名和密码存入一个新的文件当中;
再通过访问文件,对存入的数据进行处理后,与用户登录时的用户名与密码进行对比判断
username = input('请输入用户:') password = input('请输入密码:') with open('账户信息','w+',encoding='utf-8',) as user: info = user.write('{}\n{}'.format(username,password)) print('恭喜你,注册成功') i = 3 lis = [] while i > 0: i -= 1 um = input('请输入账户名:') pwd = input('请输入密码:') with open('账户信息', 'r+', encoding='utf-8', ) as user1: for line in user1: lis.append(line) if um == lis[0].strip() and pwd == lis[1].strip(): print('欢迎'+lis[0].strip()) break elif i > 0: print('账户名或密码错误,还剩{}次机会'.format(i)) else:print('账户已被锁定')
知识点:格式化输出、文件的基本操作