zoukankan      html  css  js  c++  java
  • 3.14周末作业

    二:周末综合作业:
    2.1:编写用户登录接口
    1、输入账号密码完成验证,验证通过后输出"登录成功"

    name='egon'
    pwd='123'
    inp_name=input('your name:').strip()
    inp_pwd=input('yoour pwd:').strip()
    if inp_name == name and inp_pwd == pwd:
        print('登录成功')
    else:
        print('用户名或密码错误')
    2、可以登录不同的用户
    users={
        'egon':'123',
        'alex':'777',
        'oldboy':'nb'
    }
    inp_name=input('your name:').strip()
    inp_pwd=input('your pwd:').strip()
    if inp_name in users:
        if inp_pwd == users[inp_name]:
            print('登录成功')
        else:
            print('密码错误')
    else:
        print('用户名错误')
    

    3、同一账号输错三次锁定,(提示:锁定的用户存入文件中,这样才能保证程序关闭后,该用户仍然被锁定)

    dic={
        'egon1':['mxc',0],
        'egon2':['222',0],
        'egon3':['333',0],
    }
    
    count=0
    while True:
        name=input('u>>: ')
        if name not in dic:
            print('用户不存在')
            continue
    
        with open('db.txt','r') as f:
            lock_users=f.read().split('|')
            if name  in lock_users:
                print('用户%s已经被锁定' %name)
                break
    
        if dic[name][1] > 2:
            print('尝试次数过多,锁定')
            with open('db.txt','a') as f:
                f.write('%s|' %name)
            break
    
        password=input('p>>: ')
    
        if password == dic[name][0]:
            print('登录成功')
            break
        else:
            print('用户名或密码错误')
            dic[name][1]+=1
    

    2.2:编写程序实现用户注册后,可以登录,
    提示:

    while True:
        msg = """
        0 退出
        1 登录
        2 注册
        """
        print(msg)
        cmd = input('请输入命令编号>>: ').strip()
        if not cmd.isdigit():
            print('必须输入命令编号的数字,傻叉')
            continue
    
        if cmd == '0':
            break
        elif cmd == '1':
            count = 0
            while count < 3:
                inp_name=input('your name:').strip()
                inp_pwd=input('your password:').strip()
                with open(r'users.txt',mode='rt',encoding='utf-8') as f:
                    for line in f:
                        names,password=line.strip().split(':')
                    if inp_name == names:
                        if inp_pwd == password:
                            print('登录成功')
                            break
                        else:
                            print('密码错误')
                            count+=1
                    else:
                        print('用户不存在')
                        count+=1
            break
        elif cmd == '2':
            tag=True
            while tag:
                print('秀儿,请开始你的表演')
                name2=input('请输入注册用户名:').strip()
                pwd2=input('请输入密码:').strip()
                with open(r'users.txt', mode='r+t', encoding='utf-8') as f:
                    for d in f:
                        xx2, pwd2 = d.strip().split(':')
                    if name2 ==xx2:
                        print('用户已存在,请重新输入')
                        continue
                    else:
                        f.write('{}:{}
    '.format(name2,pwd2))
                        print('注册成功')
                        tag=False
            break
        else:
            print('输入的命令不存在')
        # 思考:上述这个if分支的功能否使用其他更为优美地方式实现
    
  • 相关阅读:
    用 ArcMap 发布 ArcGIS Server FeatureServer Feature Access 服务 PostgreSQL 版本
    ArcMap 发布 ArcGIS Server OGC(WMSServer,MapServer)服务
    ArcScene 创建三维模型数据
    ArcMap 导入自定义样式Symbols
    ArcMap 导入 CGCS2000 线段数据
    ArcMap 导入 CGCS2000 点坐标数据
    ArcGis Server manager 忘记用户名和密码
    The view or its master was not found or no view engine supports the searched locations
    python小记(3)操作文件
    pytest(2) pytest与unittest的区别
  • 原文地址:https://www.cnblogs.com/linqiaobao/p/12496788.html
Copyright © 2011-2022 走看看