• 20.01.16作业


    # 2.1:编写用户登录接口
    #1、输入账号密码完成验证,验证通过后输出"登录成功"
    #2、可以登录不同的用户
    #3、同一账号输错三次锁定,(提示:锁定的用户存入文件中,这样才能保证程序关闭后,该用户仍然被锁定)
    
    user_name=input('请输入用户名: ')
    password=input('请输入密码: ')
    tag = True
    count=0
    with open('pwd.txt',mode='rt',encoding='utf-8') as file1,
            open('lock.txt',mode='rt',encoding='utf-8') as file2:
        for i in file2:
            lock_name,lock_pwd=i.strip().split(':')
            if user_name==lock_name :
                print('该账号已被冻结')
                tag = False
                break
            else:
                continue
        while tag:
            for j in file1:
                name,pwd=j.strip().split(':')
                if user_name==name and password==pwd:
                    print('登录成功')
                    tag=False
            else:
                print('登录失败!')
                count+=1
                if count==3:
                    print('失败三次')
                    with open('lock.txt',mode='at',encoding='utf-8')as file3:
                        res=('{}:{}
    '.format(user_name,password))
                        file3.write(res)
                    tag=False
                    break
                else:
                    user_name = input('请再次输入用户名: ')
                    password = input('请再次输入密码: ')
    复制代码
    复制代码
    # 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':
            n = 0
            tag = True
            while tag:
                user_name = input('请输入用户名: ')
                password = input('请输入密码: ')
                with open('pwd.txt', mode='rt', encoding='utf-8')as file1:
                    for i in file1:
                        name, pwd = i.strip().split(':')
                        if user_name == name and password == pwd:
                            print('登录成功!')
                            tag = False
                            break
                    else:
                        print('账号或密码错误!')
                        n += 1
                        if n == 3:
                            tag = False
            break
        elif cmd == '2':
            user_name = input('请输入注册id:')
            password = input('请输入注册密码: ')
            with open('pwd.txt', mode='at', encoding='utf-8')as file2:
                res = ('{}:{}
    '.format(user_name, password))
                file2.write(res)
                print('注册成功!')
            break
        else:
            print('输入的命令不存在')
     
  • 相关阅读:
    nvidia-smi电源显示ERR (Pwr:Usage ERR)
    阿里云windows安装ftp
    ansible常用模块
    ansible playbook
    ansible Inventory
    ansible安装
    ansible命令
    ansible配置文件
    js插件中提示框含有 或者<br/>显示不成换行怎么办,改样式
    [转] react项目安装及运行
  • 原文地址:https://www.cnblogs.com/zhangjinyi97/p/12502216.html
Copyright © 2020-2023  润新知