编写登录接口 & 简单进度条

Posted on 2018-03-05 10:01  Brown羊羊  阅读(138)  评论(0编辑  收藏  举报

登录接口

需求:

输入用户名密码

认证成功后返回欢迎信息

输入错误三次后锁定

 

 1 # -*- coding:utf-8 -*- 
 2 # Author:Brownyangyang
 3 #import getpass
 4 import sys
 5 count=0
 6 p=0
 7 #username = input("username:")
 8 while count < 3:
 9     username = input ("username:")
10     f = open("lock_file.txt",'r+')
11     lock_list=f.readlines()
12     for lock_line in lock_list:
13         lock_line = lock_line.strip('\n')
14         if username == lock_line:
15             sys.exit('用户 %s 已经被锁定,退出' % username)
16 
17     k = open('user_list.txt','r')
18     user_list = k.readlines()
19     for user_line in user_list:
20         (user,passwd) = user_line.strip('\n').split()
21         if username == user:
22             j=0
23             while j<3:
24                 password = input ("password:")
25                 if password == passwd:
26                     print("Welcome,用户%s!!!" % username)
27                     sys.exit(0)
28                 else:
29                     print("用户%s密码错误" % username)
30                 j += 1
31             else:
32                 f.write(username+'\n')
33                 sys.exit("用户%s达到最大登录次数,退出。" % username)
34 
35         else:
36              pass
37     count += 1
38     print("用户 %s 不存在,请重新输入" % username)
39 else:
40     sys.exit("用户 %s 不存在,退出" % username)
41 
42 f.close()
43 k.close()

 

简单进度条

# -*- coding:utf-8 -*- 
# Author:Brownyangyang
import sys,time
for i in range(30):
    sys.stdout.write(">>")
    sys.stdout.flush()
    time.sleep(0.5)