zoukankan      html  css  js  c++  java
  • 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()
  • 相关阅读:
    Hive快速入门
    Spark Standalone 提交模式
    Spark WordCount 文档词频计数
    Spark Shuffle原理分析及性能优化
    Spark性能问题分析及优化【OOM、Stack Overflow】
    Redis常用命令【列表】
    Redis常用命令【字符串】
    Nosql数据库分类
    Redis内存数据库快速入门
    Scrapy实现腾讯招聘网信息爬取【Python】
  • 原文地址:https://www.cnblogs.com/laotieshan/p/13207648.html
Copyright © 2011-2022 走看看