密码保存
password_list = ['*#*#','12345']def account_login():
tries = 3
while tries > 0:
password = input("请输入密码:")
password_correct = password == password_list[-1]
password_reset = password == password_list[0]
if password_correct:
print('登录成功!')
break
elif password_reset:
new_password = input('请设置新密码:')
password_list.append(new_password)
password_list == password_list.pop(1)
print('你的密码已经重置!')
#account_login()
else:
print('密码错误,请重新输入!')
tries = tries - 1
print('还有',tries,'次机会')
else:
print('输入错误次数过多,已锁定')
account_login()
新建一个名为data.txt的文本文件
内容输入
*#*#
12345
修改代码
with open('data.txt') as f:
password_list = f.read().split('\n')
def account_login():
tries = 3
while tries > 0:
password = input("请输入密码:")
password_correct = password == password_list[-1]
password_reset = password == password_list
if password_correct:
print('登录成功!')
break
elif password_reset:
new_password = input('请设置新密码:')
password_list.append(new_password)
password_list == password_list.pop(1)
print('你的密码已经重置!')
#account_login()
else:
print('密码错误,请重新输入!')
tries = tries - 1
print('还有',tries,'次机会')
else:
print('输入错误次数过多,已锁定')
account_login()
with open('data.txt','w') as f:
f.write('\n'.join(password_list))
页:
[1]