标签:input write key continue 用户 open 源码 word span
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
标签:input write key continue 用户 open 源码 word span
原文地址:https://www.cnblogs.com/skings/p/10213441.html