python 3次登录
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 3次登录相关的知识,希望对你有一定的参考价值。
1 #!/usr/bin/env python 2 #_*_ coding:utf-8 _*_ 3 #三次登录 4 import sys,os 5 os.system(‘clear‘) 6 retry_limit = 3 7 retry_count = 0 8 account_file = ‘account.txt‘ 9 lock_file = ‘account_lock.txt‘ 10 11 def lock(username): 12 f = open(lock_file, ‘rb‘) 13 for line in f.readlines(): 14 if username == line.strip(‘\n‘): 15 sys.exit(‘User %s is locked!!!‘ % username) 16 17 18 def login(username,password): 19 global retry_count 20 while retry_count < retry_limit: 21 f = open(account_file, ‘rb‘) 22 match_flag = False 23 for line in f.readlines(): 24 user,passwd = line.strip(‘\n‘).split() 25 if username == user and password == passwd: 26 print (‘hello, %s !!‘ % username) 27 match_flag = True 28 break 29 f.close() 30 31 if match_flag == False: 32 print(‘sorry, %s is error‘ %username) 33 retry_count += 1 34 else: 35 print(‘welcome login %s!!!!‘ %username) 36 braek 37 else: 38 print ("you account %s is locked!!!" % username) 39 g = open(lock_file,‘a‘) 40 g.write(username) 41 g.write(‘\n‘) 42 g.close() 43 44 45 def main(username, password): 46 lock(username) 47 login(username,password) 48 49 50 username = raw_input("username:") 51 password = raw_input("password") 52 main(username, password) 53 54 55 56 #def main(): 57 # username = raw_input("username:") 58 # password = raw_input("password") 59 # lock(username) 60 # login(username,password) 61 #main()
以上是关于python 3次登录的主要内容,如果未能解决你的问题,请参考以下文章