先注册,将用户名和密码写入文件,然后三次机会登录,将文件中的信息读出与输入的信息比较
#换行符 \n
#s.strip() 除去字符串两端的空格或换行符
username = input('请输入你要注册的用户名:')password = input('请输入你要注册的密码:')with open('list_of_info',mode='w',encoding='utf-8') as f: f.write('{}\n{}'.format(username,password))print('恭喜您,注册成功')lis = []i = 0while i < 3: usn = input('请输入你的用户名:') pwd = input('请输入你的密码:') with open('list_of_info',mode='r+',encoding='utf-8') as f1: for line in f1: lis.append(line) if usn == lis[0].strip() and pwd == lis[1].strip(): print('登录成功') break else:print('账号和密码错误') i+=1