首页 > 代码库 > Python-基础练习题2
Python-基础练习题2
编写登陆接口
- 输入用户名密码
- 认证成功后显示欢迎信息
- 输错三次后锁定
#!/usr/bin/env python # _*_ coding:utf8 _*_ import getpass Username = ‘daxin‘ Password = ‘123456‘ def panduan(name): with open(‘/tmp/result.log‘) as fd: content = fd.read() if len(content) == 0: return True else: lockname = content.split()[0] zhuangtai = content.split()[1] if lockname == name and zhuangtai == ‘lock‘: return False else: return True count = 0 while count < 3: username = raw_input(‘login:‘) password = getpass.getpass(‘password:‘) result = panduan(username) if result: if username == Username and password == Password: print "欢迎登陆" break elif username != Username: print "用户名不存在!,请注册!" break else: print ‘用户名/密码错误‘ break count += 1 else: print ‘帐号已经锁定!‘ break else: print ‘帐号已经锁定!‘ with open(‘/tmp/result.log‘,‘r+‘) as fd: fd.write(‘daxin lock‘)
Python-基础练习题2
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。