python作业:编写登陆接口

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python作业:编写登陆接口相关的知识,希望对你有一定的参考价值。

python作业:编写登陆接口

要求:

1.要求用户输入用户名和密码

2.认证成功显示欢迎信息

3.输入错误超过三次锁定用户

 

 1 #!/usr/bin/env python
 2 #_*_coding:utf-8_*_
 3 #__author__ = ‘Administrator‘
 4 
 5 static=True
 6 login=False
 7 username=‘‘
 8 lockfile=rlock.txt
 9 for i in range(3):
10     username=input("please input your username:")
11     password=input("please input your password:")
12 
13     
14     with open(lockfile,r) as lockobject:
15          users=lockobject.readlines()
16          for line2 in users:
17              line2=line2.strip(\n)
18 
19              if line2 == username:
20                  static=False
21                  break
22 
23     if static==False:
24         break
25 
26 
27     with open(ruser.txt,r) as user:
28          users=user.readlines()
29     for line in users:
30         userinfo="|".join([username,password])
31         line=line.strip(\n)
32         if userinfo == line:
33             print(welcome {username} !.format(username=username))
34             login=True
35             break
36 
37     if login:
38         break
39     else:
40          print(Invalid username and password!\n)
41 
42 if login==False:
43     if static:
44         with open(lockfile,a) as lockobject:
45              line_string=‘‘.join([username,\n])
46              lockobject.write(line_string)
47     print("lock!")

 

以上是关于python作业:编写登陆接口的主要内容,如果未能解决你的问题,请参考以下文章

Python学习作业之登陆接口_While

Python学习作业之登陆接口_For

python之编写登陆接口

python之编写登陆接口(第一天)

day1作业:编写登陆接口

python第一天作业1