day17作业

猜年龄游戏

age = 18  
count = 0  
prize_dict = {0: '气娃娃', 1: '变形金刚', 2: '飞飞杯', 3: '<Python从入门到放弃>'}

while count < 3:
    inp_age = input('请输入你的年龄>>>')  

    if not inp_age.isdigit():
        print('年龄输错了!!!')
        continue
    
    inp_age_int = int(inp_age)
    
    if inp_age_int == age:
        print('猜对了')
    
        print(prize_dict)  
    
     
        for i in range(2):
            prize_choice = input(
                '请输入你想要的奖品,如果不想要,则输入"n"退出!!!')  
    
    
            if prize_choice != 'n':
                print(f'恭喜你获得奖品: {prize_dict[int(prize_choice)]}')
            else:
                break
        break
    
    elif inp_age_int < age:
        print('猜小了')
    
    else:
        print('猜大了')
    
    count += 1  
    
    if count != 3:
        continue
    
    again_choice = input('是否继续游戏,继续请输入"Y",否则任意键直接退出.')  
    
    
    if again_choice == 'Y':
        count = 0
        

三级菜单

menu = {
    'beijing': {
        'haidin': {
            'wudaokou': {
                'soho': {},
                'wangyi': {},
                'google': {}
            },
            'zhongguancun': {
                'aiqiyi': {},
                'qichezhiija': {},
                'youku': {},
            },
            'shangdi': {
                'baidu': {},
            },
        },
        'changping': {
            'shahe': {
                'oldboy': {},
                'beihang': {},
            },
            'tiantongyuan': {},
            'huilongguan': {},
        },
        'zhaoyang': {},
        'dongcheng': {},
    },
    'shanghai': {
        'minhang': {
            "renminguangchang": {
                'zhajidian': {}
            }
        },
        'zhabei': {
            'huochezhan': {
                'xiecheng': {}
            }
        },
        'pudong': {},
    },
    'shandong': {},
}

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

转载于:https://www.cnblogs.com/Isayama/p/11523991.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值