zoukankan      html  css  js  c++  java
  • Day10 作业

    Day10 作业

    prize_dict = {
        '0': "芭比娃娃",
        '1': "变形金刚",
        '2': "psp游戏机",
        '3': "奥特曼",
        '4': "遥控飞机",
        '5': "chongqiwawa",
    }
    
    # 注册
    def register():
        user_name = input("用户名:
    ").strip()
        passwd_1 = input("密码:
    ").strip()
        passwd_2 = input("再次输入密码:
    ").strip()
        if passwd_1 == passwd_2:
            with open("user_info.txt", "a") as fa:
                fa.write(f"{user_name}:{passwd_1}
    ")
            print("注册成功")
        else:
            print("两次密码输入不一致")
    
    def login():
        count = 0
        while count < 3:
            user_name = input("用户名:
    ").strip()
            passwd = input("密码:
    ").strip()
            with open("user_info.txt", "r") as fr:
                for info in fr:
                    usr_info, passwd_info = info.strip().split(":")
                    if user_name == usr_info and passwd == passwd_info:
                        print('登陆成功')
                        return True
            count += 1
    
    # 猜年龄
    def guess_age(age):
        count = 0
        while count < 3:
            inp_age = input("请输入年龄:
    ").strip()
            if not inp_age.isdigit():
                print("请输入整数")
                continue
            inp_age = int(inp_age)
            if inp_age == age:
                print("猜对了")
                return  True
            elif inp_age > age:
                print("猜大了")
            else:
                print("猜小了")
            count += 1
    
    # 给奖品
    def choose_prize():
        prize_lst = []
        while len(prize_lst) < 2:
            print(prize_dict)
            inp = input("请选择奖品:
    ")
            if inp in prize_dict:
                prize = prize_dict[inp]
                prize_lst.append(prize)
                print(f"选择了:{prize}")
            else:
                print("选项不在列表中,请重新选择")
        print(f"选择的奖品有:{prize_lst}")
    
    age = 26
    inp = input("1:注册, 2:登陆
    ").strip()
    if inp == "1":
        register()
    elif inp == "2":
        if not login():
            print("登陆失败")
            exit()
        if not guess_age(age):
            print("猜测年龄失败")
            exit()
        choose_prize()
    else:
        print("输入错误,请重新输入")
    
    
  • 相关阅读:
    mongodb 3.4复制搭建
    mongodb 用户管理
    mongodb 3.4 TAR包启动多个实例
    mongodb 3.4 YUM安装
    mongodb数据库备份恢复-windows系统
    mongodb数据库索引管理
    mongodb数据库集合操作
    Unity3d 实现鼠标左键点击地形使角色移动到指定地点[脚本]
    Unity3D性能优化之Draw Call Batching
    Unity3D占用内存太大怎么解决呢?
  • 原文地址:https://www.cnblogs.com/YajunRan/p/11551894.html
Copyright © 2011-2022 走看看