zoukankan      html  css  js  c++  java
  • 02作业

    登录接口作业

    1 编写登录接口

    实现需求

    • 让用户输入用户名密码
    • 认证成功后显示欢迎信息
    • 输错三次后退出程序
    name_of_guest = 'thales'
    pwd_of_guest = 'passwd'
    
    print('开始登陆')
    count = 0
    while True:
        if count == 3:
            print('输入次数太多,请稍后重试')
            break
        name = input('请输入你的名字:')
        pwd = input('请输入你的密码:')
        if name == name_of_guest and pwd == pwd_of_guest:
            print('登陆成功,welcome to website')
            break
        else:
            print('账户或密码错误,请重试')
            count += 1
    print('结束')

    2 需求增加

    • 可以支持多个用户登录 (提示,通过列表存多个账户信息)
    • 用户3次认证失败后,退出程序,再次启动程序尝试登录时,还是锁定状态(提示:需把用户锁定的状态存到文件里)
    count = 0
    dic = {
        'name1': {'password': '123', 'count': 1},
        'name2': {'password': '234', 'count': 0},
        'name3': {'password': '345', 'count': 1}
    }
    while True:
        input_name = input('请输入你的名字>>')
        if input_name not in dic:
            print('账号不存在')
            continue
            
        with open('erro.txt', 'r') as f:
            look_users = f.read().split('|')
            if input_name in look_users:
                print('用户已被锁定')
                break
        if dic[input_name]['count'] > 1:
            print('账号被锁定')
            with open('erro.txt', 'w') as f:
                f.write('%s|' % input_name)
            break
            
        password = input('你的密码啊>>')
        if password == dic[input_name]['password']:
            print('登陆成功')
        else:
            print('用户名或密码错误')
            dic[input_name]['count'] += 1
  • 相关阅读:
    1月19号 UIImageView
    1月18号 UILabel 加上导入.tff格式的字体
    1月18号 UIButton
    2016年 1月15号 cocoapods的导入
    1月12号 UIView
    12月30号 iOS程序准备
    12月29号 计算器(包含混合运算)
    2016.01.13 代理设计模式
    2016.01.04 视图控制器UIViewController
    2015.12.31 iOS程序准备(developer.apple.com)
  • 原文地址:https://www.cnblogs.com/zuanzuan/p/9650260.html
Copyright © 2011-2022 走看看