• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
隐身
不能改变社会,就要学会改变自己
博客园    首页    新随笔    联系   管理    订阅  订阅

编写登陆接口

要求:

  • 输入用户名密码
  • 认证成功后显示欢迎信息
  • 输错三次后锁定
user = [['yefei','123'],['yf','123'],['mm','123']]
count = 0
error_count = 0
while count < 3:
    user_name = input("请输入用户名:").strip()
    user_password = input("请输入密码:").strip()
    f = open(file= 'error.txt',mode='r',encoding='utf-8')
    data = f.read()
    if user_name in data:
        print("对不起!用户%s被锁定!请使用其它用户名登录!" % user_name)
    else:
        for i,v in enumerate(user):
            if user_name == v[0] and user_password == v[1]:
                print("欢迎,登陆成功!")
                exit()
            else:
                f = open(file='error.txt',mode='a+',encoding='utf-8')
                error_count += 1
                if error_count == 9:
                    f.write('%s状态:锁定' % user_name)
        print('您的用户密码输入有误!')
    count += 1
    f.close()

测试结果如下:

 

posted @ 2019-02-19 10:15  隐身哈  阅读(148)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3