ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

day06

2019-09-16 09:50:41  阅读:165  来源: 互联网

标签:menu age tag day06 continue key print


1.猜年龄游戏:

要求:

    允许用户最多尝试3次
    每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y, 就继续让其猜3次,以此往复,如果回答N或n,就退出程序
    如果猜对了,有三次选择奖励的机会,不要奖励可以随时退出,并打印奖品清单给用户看;
age = 18
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

2.三级菜单:

  1. 打印省、市、县三级菜单
  2. 可返回上一级
  3. 可随时退出程序
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 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

标签:menu,age,tag,day06,continue,key,print
来源: https://www.cnblogs.com/yu521/p/11525751.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有