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

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

    新建user.txt
    import time
    count=0 while count<3: in_name = input("请输入您的账号:").strip() in_pwd = input("请输入您的密码:").strip() with open('user.txt', mode='rt', encoding='utf-8') as f: for i in f: username, userpwd = i.strip().split(":") if in_name == username and in_pwd == userpwd: print('登录成功') count=3 else: print("账号或者密码错误") count += 1 if count==3: with open('users.txt',mode='at',encoding='utf-8') as f1: f1.write(in_name)
    time.sleep(5) print("账号已被锁定") break

      

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

    提示:
    while True:
    msg = """
    0 退出
    1 登录
    2 注册
    """
    print(msg)
    cmd = input('请输入命令编号>>: ').strip()
    if not cmd.isdigit():
    print('必须输入命令编号的数字,傻叉')
    continue 

      

    while True:
        msg = """
        0 退出
        1 登录
        2 注册
        """
        print(msg)
        cmd = input('请输入命令编号>>: ').strip()
        if not cmd.isdigit():
            print('必须输入命令编号的数字,傻叉')
            continue
    
        if cmd == '0':
            break
        elif cmd == '1':
            in_name = input("请输入您的账号:").strip()
            in_pwd = input("请输入您的密码:").strip()
            with open('user.txt', mode='rt', encoding='utf-8') as f:
                for a in f:
                    username, userpwd = a.strip().split(":")
                    if in_name == username and in_pwd == userpwd:
                        print('登录成功')
                    else:
                        print("账号或者密码错误")
        elif cmd == '2':
            in_name = input("请输入您的账号:").strip()
            in_pwd = input("请输入您要设置的密码:").strip()
            with open('user.txt', mode='at', encoding='utf-8') as f1:
                f1.write('{}:{}
    '.format(in_name,in_pwd))
                print('设置成功')
                break
        else:
            print('输入的命令不存在')
    

      

  • 相关阅读:
    Linux如何查找大文件或目录总结
    Linux下动态调整LVM文件系统大小
    ios学习路线图
    js模块,类,继承,命名空间,私有属性等相关概念梳理
    <代码大全2>记录
    2017读书计划
    Spring声明式事务
    Spring-Aop
    Spring静态工厂和扫描器
    Spring-IOC
  • 原文地址:https://www.cnblogs.com/Tornadoes-Destroy-Parking-Lots/p/12499961.html
Copyright © 2011-2022 走看看