zoukankan      html  css  js  c++  java
  • 2020Python练习七——文件处理2

    2020Python练习七——文件处理2

    @2020.3.15

    周末综合作业:


    1、编写用户登录接口
    #1、输入账号密码完成验证,验证通过后输出"登录成功"
    #2、可以登录不同的用户
    #3、同一账号输错三次锁定,(提示:锁定的用户存入文件中,这样才能保证程序关闭后,该用户仍然被锁定) 

    username1 = input('请输入你的名字:').strip()
    usercode1 = input('请输入你的密码:').strip()
    count=0
    with open(r'D:temptdb.txt',mode='rt',encoding='utf-8') as f:
        for line in f: #把用户输入的名字和密码与读出的内容作对比
            username,usercode=line.strip('').split(':')
            if username1 == username and usercode1 == usercode:
                print('登录成功')
                break
            else:
                print('账号或密码错误,请重试')
                count+=1
        else:
            print('账号或密码输错三次,账户已被锁定,请申请找回或修改密码')
            with open(r'D:temptclockeduser.txt',mode='wt',encoding='utf-8') as f:
                f.write('{}:{}'.format(username1,usercode1))

    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':
    # 登录功能代码(附加:可以把之前的循环嵌套,三次输错退出引入过来)
    pass
    elif cmd == '2':
    # 注册功能代码
    pass
    else:
    print('输入的命令不存在')

    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
    with open(r'D:temptdb.txt',mode='rt',encoding='utf-8') as f:
        for line in f: #把用户输入的名字和密码与读出的内容作对比
            username,usercode=line.strip('').split(':')
            if username1 == username and usercode1 == usercode:
                print('登录成功')
                break
            else:
                print('账号或密码错误,请重试')
                count+=1
        else:
            print('账号或密码输错三次,账户已被锁定,请申请找回或修改密码')
            with open(r'D:temptclockeduser.txt',mode='wt',encoding='utf-8') as f:
                f.write('{}:{}'.format(username1,usercode1))
            
        elif cmd == '2':
            # 注册功能代码
             print("注册账号".center(40,"="))
            info = {}
            name = input("账号名:").strip()
            pwd = input("账号密码:").strip()
            # 读取文件中已存在的账号密码信息
            with open("test1","r",encoding="utf-8") as f:
                for line in f:
                    user_name, password = line.strip().split("-")
                    info[user_name] = password
        else:
            print('输入的命令不存在')
  • 相关阅读:
    控制HTML Input只能输入数字和小数点
    VS中的路径宏 vc++中OutDir、ProjectDir、SolutionDir各种路径
    C# ListView用法详解
    wordpress学习五: 通过wordpress_xmlrpc的python包远程操作wordpress
    用IDEA开发简单的Servlet
    在centOS中安装mongodb
    simhash-- 一种文档去重的算法
    一个java实现的简单的4则运算器
    搭建ZooKeeper
    java入门--4111:判断游戏胜者-Who Is the Winner
  • 原文地址:https://www.cnblogs.com/bigorangecc/p/12501113.html
Copyright © 2011-2022 走看看