day1-登录系统
Posted a10086
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了day1-登录系统相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env python # -*- coding: utf-8 -*- import getpass file=open(‘passwd.txt‘,‘r‘,encoding=‘utf-8‘) filewrong=open(‘passwd_wrong.txt‘,‘r‘,encoding=‘utf-8‘) login_pwd=eval(file.read()) login_wrong=eval(filewrong.read()) file.close() filewrong.close() i=1 list=[] list=login_wrong login="err" while i<=3 : account = input("Account:") password = getpass.getpass("password;") if account in login_wrong: print("user locked!!") else: for i2 in range(len(login_pwd)): if account == login_pwd[i2][0]: login="user" if password == login_pwd[i2][1]: print("login success!") login="success" break else: print("Try Again!!You only have %d chances left." % (3 - i)) i+=1 else: login="nouser" if login=="nouser": print("user:%s no exit!!" % account) if login=="success": break else: print("user locked!!") filewrong=open(‘passwd_wrong.txt‘,‘w‘,encoding=‘utf-8‘) list.append(account) print(str(list)) data=str(list) filewrong.write(data) filewrong.close()
文件1 passwd.txt
[["abc123","password"],["aaa","bbb"]]
文件2 passwd_wrong.txt
[‘abc123‘]
以上是关于day1-登录系统的主要内容,如果未能解决你的问题,请参考以下文章