改之前:
#登陆,从user_info.txt中验证
count=1
#print(count)
f = open('user_info.txt','a+')
f.seek(0)
user_info = f.read()
while count<=3:
name = input("请输入您的姓名:").strip()
password = input("请输入您的密码:").strip()
if name in user_info and password in user_info:
print("欢迎"+name+"登录")
break
elif len(name)==0 or len(password)==0:
print("请不要输入空格")
count += 1
else:
print("账号密码错误!!")
count+=1
else:
print("输入错误次数过多!!")
f.close()
改之后:
#登陆,从user_info.txt中验证
count=1
#print(count)
f = open('user_info.txt','a+',encoding='utf-8')
f.seek(0)
user_info = f.read()
while count<=3:
name = input("请输入您的姓名:").strip()
password = input("请输入您的密码:").strip()
if name and password :
if name in user_info and password in user_info:
print('登录成功')
break
else:
print('账号密码错误!!')
count+=1
else:
print("账号密码不能为空!!")
count+=1
else:
print("输入错误次数过多!!")
f.close()