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

Python-基础练习题2

时间:2016-11-27 00:07:24      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:存在   lock   错误   int   with   用户名   put   认证   nbsp   

编写登陆接口

  • 输入用户名密码
  • 认证成功后显示欢迎信息
  • 输错三次后锁定
#!/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

标签:存在   lock   错误   int   with   用户名   put   认证   nbsp   

原文地址:http://www.cnblogs.com/dachenzi/p/6105509.html

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