• 2020-6-29-Python3-day1作业


     1 # -*- coding:utf-8 -*-
     2 __author__ = 'admin'
     3 '''
     4 locked.txt:
     5 liuxiaoyu
     6 xiaodong
     7 tenglan
     8 match.txt:
     9 alex 123456
    10 xiaoyu 6543210
    11 wulongyuan 6667770
    12 '''
    13 import sys
    14 
    15 account_file = 'c:python作业day1match.txt'
    16 locked_file = 'c:python作业day1locked.txt'
    17 
    18 def deny_account(user_name):
    19     print('您的用户 %s 已被锁定!' % user_name)
    20     with open(locked_file, 'a') as deny_f:
    21         deny_f.write('
    ' + user_name)
    22 
    23 def main():
    24     retry_count = 0
    25     retry_limit = 3
    26     while retry_count < retry_limit:
    27         user_name = input('33[32;1m请输入用户名:33[0m')
    28         #判断用户名是否为空
    29         if len(user_name) == 0:
    30             print('用户名不能为空,请重新输入!')
    31             continue
    32         #判断用户名是否被锁定
    33         with open(locked_file, 'r') as lock_f:
    34             for line in lock_f:
    35                 if len(line.strip()) == 0:
    36                     continue
    37                 if user_name == line.strip():   #strip()去掉两侧的空格和
    
    38                     sys.exit('33[32;1m用户 %s 已经被锁定!33[0m' % user_name)
    39         #判断密码是否为空
    40         while True:
    41             password = input('33[32;1m请输入密码:33[0m')
    42             if len(password) == 0:
    43                 print('密码不能为空,请重新输入!')
    44                 continue
    45             else:
    46                 break
    47         #判断用户名和密码是否相符
    48         with open(account_file, 'r') as account_f:
    49             flag = False
    50             for line in account_f:
    51                 #跳过空行
    52                 if len(line.strip()) == 0:
    53                     continue
    54                 user, pawd = line.strip().split()
    55                 if user_name == user and password == pawd:
    56                     print('success!')
    57                     flag = True
    58                     break
    59         #判断错误次数是否超过3次
    60         if flag == False:
    61             if retry_count < 2:
    62                 print('您的用户名或密码有误,请重新输入!')
    63             retry_count += 1
    64             continue
    65         else:
    66             print('欢迎用户%s登陆老男孩系统!' % user_name)
    67             break
    68     else:
    69         deny_account(user_name)
    70 
    71 if __name__ == '__main__':
    72     main()
  • 相关阅读:
    windows 共享文件夹 给 mac
    给mac配置adb 路径
    关于android 加载https网页的问题
    http tcp udp ip 间的关系
    手机服务器微架构设计和实现专题
    添加ssh key
    本人对于线程池的理解和实践
    使用Android Butterknife
    记一次失败的笔试(华为研发工程师-汽水瓶笔试题)
    简易坦克大战python版
  • 原文地址:https://www.cnblogs.com/laotieshan/p/13207648.html
Copyright © 2020-2023  润新知