python 3次登入

來源:互聯網
上載者:User

標籤:exit   raw_input   login   try   name   bin   log   limit   write   

 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_count20     while retry_count < retry_limit:21         f = open(account_file, ‘rb‘)22         match_flag = False23         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 = True28                 break29         f.close()30     31         if match_flag == False:32             print(‘sorry, %s is error‘ %username)33             retry_count += 134         else:35             print(‘welcome login %s!!!!‘ %username)36             braek37     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次登入

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.