登录界面
while 1: username =input ('请输入你的注册账号:') userkey = input('请输入你的注册密码(只能是纯数字):') if userkey.isdigit(): with open('数据存储','r+',encoding='utf-8') as f: f.write('{} \n {}'.format(username,userkey)) print("注册成功") break else: print('请输入数字') i = [] l = 0 while l < 3: user = input('请输入账号:') key1 = input('请输入密码:') with open('数据存储','r+',encoding='utf-8') as f: for line in f: i.append(line) print(i) if user == i[0].strip() and key1 == i[1].strip(): print("登录成功") break else: print('登陆失败') print('你还有{}次机会'.format(l)) l += 1
这个代码有问题,嗯.
不知为何,usrkey不能添加进入列表
待修改
修改完成
原因:将if循环列入了for循环中,导致每次只输入一个元素进入列表中
while 1: username =input ('请输入你的注册账号:') userkey = input('请输入你的注册密码(只能是纯数字):') if userkey.isdigit(): with open('数据存储','r+',encoding='utf-8') as f: f.write('{} \n {}'.format(username,userkey)) print("注册成功") break else: print('请输入数字') i = [] l = 0 while l < 3: user = input('请输入账号:') key1 = input('请输入密码:') with open('数据存储','r+',encoding='utf-8') as f: for yihang in f: i.append(yihang) print(i) if user == i[0].strip() and key1 == i[1].strip(): print("登录成功") break else: print('登陆失败') print('你还有{}次机会'.format(l)) l += 1