设为首页 加入收藏

TOP

python入门第一天作业。讲师写的代码。
2017-09-30 17:36:33 】 浏览:2774
Tags: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('\033[32; Username : \033[0m')  #输入用户名
    lock_check = open(lock_file)                             #打开锁定文件
    for line in lock_check.readlines(): 
line = line.split() #循环锁定文件跟输入的用户名比对 if uesrname == line[0]: #判断用户输入的用户名和lock文件的用户名第一元素== sys.exit('\031[31; User %s is locked!\033[0m' %username) password = raw_input('\033[32; Password : \033[0m') #输入pass f = file(account_file,'r+') match_flag = False for line in f.readlines(): #循环acc文件, user,password = lin.strip('\n').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()

作业:
编写登陆接口

输入用户名密码

认证成功后显示欢迎信息


输错三次后锁定

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇mysql-databaseython 3.4.0 with .. 下一篇1 - Django安装

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目