day06作业
猜年龄
要求:
- 给定年龄,用户可以猜三次年龄
- 年龄猜对,让用户选择两次奖励
- 用户选择两次奖励后可以退出
age = 23
count = 0
price_dic = {0: '布娃娃', 1: '变形金刚', 2: '奥特曼', 3: '《Python从入门到放弃》'}
while count < 3:
    age_inp = input('请输入你的年龄:')
    if not age_inp.isdigit():
        print('输错了,请重新输入')
        continue
    age_inp_int = int(age_inp)
    if age_inp_int == age:
        print('猜对了')
        print(price_dic)
        for i in range(2):
            prize_choice = input('请输入你想要的奖品,如果不想要,则输入"n"退出!')
            if prize_choice != 'n':
                print(f'恭喜你获得奖品: {price_dic[int(prize_choice)]}')
            else:
                break
        break
    elif age_inp_int < age:
        print('猜小了')
    else:
        print('猜大了')
    count += 1
    if count != 3:
        continue
    again_choice = input('是否继续游戏,继续请输入"Y",否则任意键直接退出.')
    if again_choice == 'Y':
        count = 0
三级菜单
要求
- 打印省、市、县三级菜单
- 可返回上一级
- 可随时退出程序
menu = {
    '北京': {
        '海淀': {
            '五道口': {
                'soho': {},
                '网易': {},
                'google': {}
            },
            '中关村': {
                '爱奇艺': {},
                '汽车之家': {},
                'youku': {},
            },
            '上地': {
                '百度': {},
            },
        },
        '昌平': {
            '沙河': {
                '老男孩': {},
                '北航': {},
            },
            '天通苑': {},
            '回龙观': {},
        },
        '朝阳': {},
        '东城': {},
    },
    '上海': {
        '闵行': {
            "人民广场": {
                '炸鸡店': {}
            }
        },
        '闸北': {
            '火车战': {
                '携程': {}
            }
        },
        '浦东': {},
    },
    '山东': {},
}
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 m 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号