zoukankan      html  css  js  c++  java
  • python入门第一天作业。讲师写的代码。

    #!/uer/bin/env python
    # _*_ coding: utf-8 _*_
    
    import sys
    retry_limit = 3
    retry_count = 0
    account_file = 'accounts.txt'
    lock_file = 'account_lock.txt'
    
    while retry_count < retry_limit:                             #循环体限制3次内执行
    
        username = raw_input('33[32; Username : 33[0m')  #输入用户名
        lock_check = open(lock_file)                             #打开锁定文件
        for line in lock_check.readlines(): 
    line = line.split() #循环锁定文件跟输入的用户名比对 if uesrname == line[0]: #判断用户输入的用户名和lock文件的用户名第一元素== sys.exit('31[31; User %s is locked!33[0m' %username) password = raw_input('33[32; Password : 33[0m') #输入pass f = file(account_file,'r+') match_flag = False for line in f.readlines(): #循环acc文件, user,password = lin.strip(' ').split() #把accounts文件拆分过滤 换行符,赋值给user,和pss变成列表 if username == user and password == password: #判断:输入的use等于acc里user 且 输入的pss等于列表里的pss print('Match!'),username match_flag = True break f.close() if match_flag == False: #判读标志位,默认不匹配。 #判断用户输入的user和pass是否与文件匹配,不配就继续循环,匹配上了就退出。 print 'User unmatched!' retry_count +=1 else : print('Welcom to in feifei blog system!') else: print("You account is locked!") f =file(lock_file,'ab') f.write(username) f.close()

    作业:
    编写登陆接口

    输入用户名密码

    认证成功后显示欢迎信息


    输错三次后锁定

  • 相关阅读:
    Web服务器的Socket通信
    Love story
    Excel初探索 - 2008/3
    One Person Game ZOJ Problem Set 3329
    只有程序员才看得懂的情书
    Collecting Bugs_poj2096
    Scout YYF I_poj3744
    hdu 3336 Count the string
    hdu 1669 Jamie's Contact Groups
    poj 1240
  • 原文地址:https://www.cnblogs.com/feifei168/p/5775835.html
Copyright © 2011-2022 走看看