有些代码看不懂是什么意思,请指教!
同一账号输错三次锁定,(提示:锁定的用户存入文件中,这样才能保证程序关闭后,该用户仍然被锁定)tag = True
dict = {}
while tag:
inp_name = input("请输入账号>").strip()
with open(r'user.txt', mode='r', encoding='utf-8') as f:
if inp_name in f:
print('该账户已被锁定')
tag = False#为什么这里要变成False??
break#这一段代码怎么理解?
inp_paw = input('输入密码>')
with open(r'user.txt', mode='rt', encoding='utf-8') as f1:
for line in f1:
name, paw = line.strip().split(':')
if name == inp_name and paw == inp_paw:
print('登陆成功')
tag = False
break
elif name == inp_name and paw != inp_paw:
print('密码错误')
if name not in dict:
dict = 0
dict = dict.get(name) + 1
if dict == 3:
with open(r'user.txt', mode='a', encoding='utf-8') as f:
f.write(name)
print('该用户被锁定')
break
else:
print('账号不存在') 本帖最后由 suchocolate 于 2020-9-11 10:04 编辑
tag = True
dict = {}
while tag:
inp_name = input("请输入账号>").strip()
with open(r'user.txt', mode='r', encoding='utf-8') as f:
if inp_name in f:
print('该账户已被锁定')
tag = False #为什么这里要变成False? ---> false表示锁定
break #这一段代码怎么理解? ---> 锁定了,就跳出循环,结束程序
inp_paw = input('输入密码>')
with open(r'user.txt', mode='rt', encoding='utf-8') as f1:
for line in f1:
name, paw = line.strip().split(':')
if name == inp_name and paw == inp_paw:
print('登陆成功')
tag = False
break
elif name == inp_name and paw != inp_paw:
print('密码错误')
if name not in dict:
dict = 0
dict = dict.get(name) + 1
if dict == 3:
with open(r'user.txt', mode='a', encoding='utf-8') as f:
f.write(name)
print('该用户被锁定')
break
else:
print('账号不存在')
页:
[1]