• day 06作业


    1、 猜年龄游戏

    1.给定年龄,用户可以猜三次年龄
    2.年龄猜对,让用户选择两次奖励
    3.用户选择两次奖励后可以退出

    import time
    
    age = 38
    count = 0
    gift_dic = {0: '布娃娃', 1: '赛车', 2: '飞机', 3: 'apple'}
    gift_inp = 0
    while count <= 3:
        age_inp = input('请猜猜年龄:')
        if not age_inp.isdigit():
            print('格式错误请重新输入', end='')
            for i in range(6):
                print('.', end='')
                time.sleep(0.2)
            continue
        age_inp_int = int(age_inp)
        if age_inp_int < age:
            print('输小了')
            time.sleep(0.3)
            count += 1
        elif age_inp_int > age:
            print('输大了')
            time.sleep(0.3)
            count += 1
        else:
            count = 3
            print('恭喜你,猜对了
    请在下列奖励中任选两样')
            print(gift_dic)
            for i in range(2):
                gift_choice = input(f'请输入你想要的第{i + 1}个奖品
    ')
                if not gift_choice.isdigit():
                    break
                if int(gift_choice) < 4:
                    print(f'恭喜你得到{gift_dic[int(gift_choice)]}!
    ')
                else:
                    break
        if count == 3:
            again_choice = input('您的对局已用完是否继续?(Y)/(N)
    ')
            if again_choice == 'Y' or again_choice == 'y':
                count = 0
            else:
                break
    
    

    2.三级菜单

    1. 打印省、市、县三级菜单
    2. 可返回上一级
    3. 可随时退出程序
    menu = {
        '北京': {
            '海淀': {
                '五道口': {
                    'soho': {},
                    '网易': {},
                    'google': {}
                },
                '中关村': {
                    '爱奇艺': {},
                    '汽车之家': {},
                    'BMW': {},
                },
                '上地': {
                    '百度': {}
                },
            },
            '昌平': {
                '沙河': {
                    '老男孩': {},
                    '北航': {}
                }
            },
            '朝阳': {},
            '东城': {}
        },
        '上海': {
            '闵行': {
                '人民广场': {},
                '炸鸡店': {}
            },
            '闸北': {
                '火车站': {
                    '携程': {}
                },
            },
            '浦东': {}
        },
        '山东': {},
    }
    tag = True
    while tag:
        menu1 = menu
        for key in menu1:
            print(key)
    
        choice1 = input('第一层>>:').strip()
    
        if choice1 == 'b':
            break
        if choice1 == 'q':
            tag = False
            continue
        if choice1 not in menu1:
            continue
    
        while tag:
            menu_2 = menu1[choice1]
            for key in menu_2:
                print(key)
    
            choice2 = input('第二层>>:').strip()
    
            if choice2 == 'b':
                break
            if choice2 == 'q':
                tag = False
                continue
            if choice2 not in menu_2:
                continue
    
            while tag:
                menu_3 = menu_2[choice2]
                for key in menu_3:
                    print(key)
    
                choice3 = input('第三层>>:').strip()
                if choice3 == 'b':
                    break
                if choice3 == 'q':
                    tag = False
                    continue
                if choice3 not in menu_3:
                    continue
    
                while tag:
                    menu_4 = menu_3[choice3]
                    for key in menu_4:
                        print(key)
    
                    choice4 = input('第四层>>:').strip()
                    if choice4 == 'b':
                        break
                    if choice4 == 'q':
                        tag = False
                        continue
                    if choice4 not in menu_4:
                        continue
    
    
  • 相关阅读:
    在jQuery中.bind() .live() .delegate() .on()的区别
    jquery小结测试题
    揭秘子类构造函数执行过程
    过滤器
    实现AJAX的基本步骤
    AJAX 原生态
    java工程师需要学什么
    Java进阶之路
    git入门大全
    轻松学JVM
  • 原文地址:https://www.cnblogs.com/LZF-190903/p/11517955.html
Copyright © 2020-2023  润新知