zoukankan      html  css  js  c++  java
  • 猜年龄游戏之函数版

    # 注册
    
    def zhuce():
        """注册一个账号"""
        count = 0
        while count < 3:
            username_inp = input('请输入你的登录名:')
            pwd_inp = input('请输入你的密码:')
            re_pwd_inp =input('请问确认你的密码:')
    
            if pwd_inp == re_pwd_inp:
                print('注册成功,请前去登录')
    
                with open(r'name_pwd.txt', 'at', encoding='utf8') as fw:
                    fw.write(f'{username_inp}:{pwd_inp}
    ')
                    fw.flush()
                    break
    
    
            else:
                print('输入有误,请重新尝试')
                count += 1
                continue
    
    
    #  登录
    def logging():
        """登录"""
        log_count = 0
    
        while log_count < 3:
            username_int_inp = input('请输入你的登陆账号:')
            pwd_int_inp = input('请输入你的密码:')
    
            with open(r'name_pwd.txt', 'r', encoding='utf8') as fr:
                for info in fr:
                    name, pwd = info.split(':')
    
                    if name.strip() == username_int_inp.strip() and pwd.strip() == pwd_int_inp.strip():
                        print('登陆成功')
                        log_count = 100
                        break
    
                else:
                    print('账号密码错误')
    
                log_count += 1
    
    
    
    
    
    #猜年龄
    
    def cainianling():
        """猜年纪"""
        import random
    
        age_count = 0
        # age = 18
        age = random.randint(1, 100)
    
        prize_dict = {
            '0': "芭比娃娃",
            '1': "变形金刚",
            '2': "psp游戏机",
            '3': "奥特曼",
            '4': "遥控飞机",
            '5': "chongqiwawa",
            '6': "再来一次",
            '7': "欢迎下次光临",
        }
    
        prize_msg = '''
        0 芭比娃娃
        1 变形金刚
        2 psp游戏机
        3 奥特曼
        4 遥控飞机
        5 chongqiwawa
        '''
    
        while age_count < 3:
            age_inp = input('请输入你猜测的年龄:')
    
            # logger.info(f'用户 {username_int_inp} 第 {age_count} 次输入年龄为 {age_inp}')
    
            if not age_inp.isdigit():
                print('傻逼,不知道什么是年龄吗?')
                continue
    
            age_inp_int = int(age_inp)  # 年龄统一成为数字
    
            if age_inp_int > age:
                print('猜大了')
                age_count += 1
                continue
    
            elif age_inp_int < age:
                print('猜小了')
                age_count += 1
                continue
    
            else:
                # print('请选择奖品')
                break
    
    
    
    
    # 选择奖品
    def xuanzejiangpin():
        """选择奖品"""
        count = 0
        while count < 1:
            print(f'奖品如下:{prize_msg}')
    
            prize_choice = input('请选择你需要的奖品:')
            prize = prize_dict[prize_choice]
    
            count += 1
    
            print(f'恭喜你获得:{prize}')
    
  • 相关阅读:
    poj 2443
    codeforces 263D
    codeforces 263C
    uva 11080
    uva 11235
    uva 11748
    STL uva 11991
    (KM) uva 11383
    (树形DP) uva 10859
    codeforces 242C
  • 原文地址:https://www.cnblogs.com/whkzm/p/11552701.html
Copyright © 2011-2022 走看看