作业一:登陆接口

 1 #作业:登陆接口
 2 user=['test','test1','test2','test3']
 3 password=['test','1test','2test','3test']
 4 count=0
 5 while True:
 6     if count > 2:
 7         print('''
 8   你操作太频繁,请稍后再试!
 9         ''')
10         break
11     name = input('your name: ')
12     pwd = input('your password: ')
13     if  not name in user:
14         print('用户名不存在')
15         continue
16     id=user.index(name)
17     if  pwd == password[id]:
18         print('欢迎登陆!')
19         break
20     else:
21         print('用户名或者密码错误!请重试')
22         count+=1
23 #进阶:
24 user=['test','test1','test2','test3']
25 password=['test','1test','2test','3test']
26 count=0
27 while True:
28     name = input('your name: ')
29     pwd = input('your password: ')
30     with open('denylogin.txt', 'r')  as file:
31         denylist = file.read()
32         if name in denylist:
33             print('你的账户已经锁定,不能登陆,请联系管理员!')
34             break
35     if  not name in user:
36         print('用户名不存在')
37         continue
38     id=user.index(name)
39     if  pwd == password[id]:
40         print('欢迎登陆!')
41         break
42     else:
43         print('用户名或者密码错误!请重试')
44         count+=1
45     if count > 2:
46         print('''你操作太频繁,账户已经锁定''')
47         with open('denylogin.txt','a') as  file :
48             file.write('%s' %name+'\n')
49             break

 

posted @ 2017-12-29 12:24  lincappu  阅读(414)  评论(0编辑  收藏  举报