码迷,mamicode.com
首页 > 编程语言 > 详细

python 练习1

时间:2017-04-13 12:33:55      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:ssd   ror   tac   rip   lock   三次   img   put   技术分享   

题目:

1.输入用户名密码
2.认证成功后显示欢迎信息
3.输错三次后锁定

 

技术分享
 1 #!/usr/bin/env python
 2 import sys,pickle
 3 account = {‘wyh‘:123,‘cloudsea‘:456}
 4 l =[]
 5 i = 0
 6 j = 0
 7 f1 = open(‘lock.txt‘,‘r‘)
 8 p = f1.readlines()
 9 for line in p:
10     s = line.strip(‘\n‘)
11     l.append(s)
12 f1.close()
13 while True:
14     name = input(‘Please input your account:‘).strip()
15     if name not in account.keys():
16         print (‘your account error,please input agen!‘)
17         i += 1
18         if i == 3:
19             print(‘You tried too many times!‘)
20             sys.exit()
21         continue
22     elif name in l:
23         print(‘Your account has been locked!‘)
24         sys.exit()
25     while True:
26         passd = int(input(‘Password:‘))
27         if passd != account[name]:
28             print(‘your password error,please try agen!‘)
29             j += 1
30             if j == 3:
31                 f = open(‘lock.txt‘,‘a‘)
32                 f.write(name + ‘\n‘)
33                 f.flush()
34                 f.close()
35                 print(‘Your account is locked, please contact your administrator!‘)
36                 sys.exit()
37             continue
38         break
39     break
40 print (‘Welcome %s into this program!‘% name)
View Code

 

python 练习1

标签:ssd   ror   tac   rip   lock   三次   img   put   技术分享   

原文地址:http://www.cnblogs.com/cloud-80808174-sea/p/6703320.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!