首页 > 代码库 > python 练习1
python 练习1
题目:
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)
python 练习1
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。