zoukankan      html  css  js  c++  java
  • 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('输入的命令不存在')
     
  • 相关阅读:
    phalcon之视图缓存
    Java NIO框架Netty教程(一) – Hello Netty
    setsockopt的作用
    支持向量机通俗导论(理解SVM的三层境地)
    quartz中的corn表达式(转)
    Applet 数字签名技术全然攻略
    SJTU 3001. 二哥的幸运
    OGRE之跳出漫长的编译等待
    VB.NET 数组的定义 动态使用 多维数组
    【Python】用Python的“结巴”模块进行分词
  • 原文地址:https://www.cnblogs.com/zhangjinyi97/p/12502216.html
Copyright © 2011-2022 走看看