用户交互程序

flog = True   #退出多重循环使用
count = 0
while count < 3:
_username = input('用户名:')
_password = input('密码:')
f1 = open(file='信息.txt',mode='r',encoding='utf-8')
for line1 in f1:
line1 = (line1.split())
username1 = line1[0]
if _username in username1:
flog = False
print('该用户已被锁定,无法登陆!!')
break#如果上述条件成立,则for循环退出
f1.close()
if not flog:
break #如果上述条件成立,则while循环退出
f = open(file='用户信息.txt',mode='r',encoding='utf-8')
for line in f:
line = (line.split())
username = line[0]
password = line[1]
if _username == username and _password == password:
flog = False
print('登陆成功!\n欢迎%s登陆'%(_username))
break #如果上述条件成立,则for循环退出
f.close()
if not flog: #如果上述条件成立,则while循环退出
break
else:
print('用户名或密码错误!!')
count += 1
if count == 3:
f1 = open(file='信息.txt',mode='a+',encoding='utf-8')
f1.write('%s\t%s\n'%(_username,_password))
f1.close()
else:
exit()
posted @ 2020-06-07 01:26  烂泥扶不上墙  阅读(50)  评论(0编辑  收藏  举报