一个小练习day1

"""
编写登陆接口
输入用户名密码
认证成功后显示欢迎信息
输错三次后锁定
"""

name = ['icing',]
passwd = ['123456',]
acount_file = 'user.txt'
i = 0
while True:
# 这个时候开始读文件
f = open(acount_file)
names = f.read().splitlines()
f.close()
i += 1
username = input('请输入您的用户名:')
if username in names:
print("您的账号%s已经被锁定,请24小时后再登录。。。"%username)
break
else:
password = input('请输入你的的密码:')
if username in name and password in passwd:
print('登陆成功!')
break
else:
# 同一个用户输入密码错误3次,写进文本后,跳出循环
if i >= 3:
# username 是否存在于文本中,存在,不写;不存在,写入
f = open(acount_file,'a+')
f.write(username+'\n')
f.close()
break
continue
posted @ 2020-09-04 17:06  蜗牛也能飞  阅读(203)  评论(0)    收藏  举报