Python-基础练习题2

编写登陆接口

  • 输入用户名密码
  • 认证成功后显示欢迎信息
  • 输错三次后锁定
#!/usr/bin/env python
# _*_ coding:utf8 _*_ import getpass Username = 'daxin'
Password = '' 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')
上一篇:Android实现无标题栏全屏的三种方法


下一篇:uboot从SD卡烧写内核和文件系统