码迷,mamicode.com
首页 > 其他好文 > 详细

用户交互程序

时间:2020-06-07 09:16:00      阅读:58      评论:0      收藏:0      [点我收藏+]

标签:open   条件   错误   循环   使用   无法   odi   count   程序   

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()

用户交互程序

标签:open   条件   错误   循环   使用   无法   odi   count   程序   

原文地址:https://www.cnblogs.com/wzq1997/p/12968696.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!