1. 程式人生 > >Python3原始碼_賬號密碼輸入介面

Python3原始碼_賬號密碼輸入介面

 1 #!/usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 #Author:SKING
 4 """
 5 題目:
 6 輸入賬號,密碼
 7 1.輸入三次後提示休息5s
 8 2.密碼重複輸入三次後鎖定賬戶
 9 """
10 
11 import string, sys, time
12 
13 def wait_5s():
14     print('You input too many times,please wait 5s...')
15     for a in range(5, 1, -1):
16         print(f'{a}s
') 17 time.sleep(1) 18 19 count = 0 #記錄使用者輸入的次數 20 count_pwd = 3 #記錄使用者輸入密碼的次數 21 22 while count<3: 23 count +=1 24 username = input('username:') 25 if username == '': 26 print('使用者名稱不能為空!請重新輸入!') 27 if count == 3: 28 wait_5s() 29 count = 0
30 continue 31 32 with open('locked_user.txt', 'r', encoding='utf-8') as file_locked_user: 33 for i in file_locked_user: 34 i = i.strip() 35 if username == i: 36 print(f'{username} is locked!') 37 chose_key = input('Press "Q" to exit!Press any key to continue:
') 38 if chose_key == 'Q' or chose_key == 'q': 39 sys.exit(0) 40 with open('user_password.txt', 'r', encoding='utf-8') as file_user_password: 41 for j in file_user_password: 42 (file_username, file_password) = j.strip().split('\t') 43 if username == file_username: 44 while count_pwd > 0: 45 print(f'You have {count_pwd} times,then will locked!') 46 password = input('password:') 47 if password == file_password: 48 print('Welcome to Python!') 49 sys.exit(0) 50 else: 51 print('Password is wrong,Please re-enter...') 52 count_pwd -= 1 53 if count_pwd == 0: 54 with open('locked_user.txt', 'r+', encoding='utf-8') as write_locked_user: 55 write_locked_user.write(username) 56 print(f'{username} is locked!') 57 sys.exit(0) 58 else: 59 print(f'{username} is not exist,Please re-enter...') 60 61 if count == 3: 62 wait_5s() 63 count = 0