zoukankan      html  css  js  c++  java
  • day 06 作业

    Python基础实战之猜数字游戏

    1.给点数字,用户可以三次猜年龄

    2.数字猜对,让用户选择两次奖励

    3.用户选择奖励后可以退出

    import time
    
    print('-' * 20, '猜数字小游戏,答对赢取超级大礼!', '-' * 20)
    time.sleep(1)
    
    print('游戏开始!你一共有三次机会哦')
    time.sleep(1)
    
    num = 18
    reward_dict = {1: '马云', 2: '雷军', 3: '马化腾'}
    count = 0
    
    while True:
        num_inp = input('请输入你猜的数字: ')
        if num_inp.isdigit() is False:
            print('输入无效')
            continue
        num_inp = int(num_inp)
        if num_inp > num:
            print('猜大了')
        elif num_inp < num:
            print('猜小了')
        else:
            print('猜对了')
            print(f'快选择你的奖品吧:{reward_dict}')
            choice = input('输入编号以选择奖品(奖品不喜欢输入其他任意内容退出): ')
            if choice in ['1', '2', '3']:
                print(f'喜提{reward_dict[int(choice)]}一只, 快去前台领奖吧!')
            break
    
        count += 1
        if count == 3:
            break
    
    print('游戏结束')
    

    Python进阶实战之三级菜单

    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:
            menu2 = menu1[choice1]
            for key in menu2:
                print(key)
    
            choice2 = input('第二层>>>: ').strip()
            if choice2 == 'b':
                break
            if choice2 == 'q':
                tag = False
                continue
            if choice2 not in menu2:
                continue
    
            while tag:
                menu3 = menu2[choice2]
                for key in menu3:
                    print(key)
    
                choice3 = input('第三层>>>: ')
                if choice3 == 'b':
                    break
                if choice3 == 'q':
                    tag = False
                    continue
                if choice3 not in menu3:
                    continue
    
                while tag:
                    menu4 = menu3[choice3]
                    for key in menu4:
                        print(key)
    
                    choice4 = input('第四层>>>: ')
                    if choice4 == 'b':
                        break
                    if choice4 == 'q':
                        tag = False
                        continue
                    if choice4 not in menu3:
                        continue
    
  • 相关阅读:
    1.1 java变量及数据类型
    3. 软件测试的类型
    2.3 软件测试模型之 敏捷测试
    2.2 软件测试的手段
    2.1 软件测试的阶段
    1.1 软件测试基础概念
    浅谈内联元素inline
    微信内置浏览器清除缓存的方法
    我的package.json清单
    我的gulp.js清单
  • 原文地址:https://www.cnblogs.com/colacheng0930/p/11530718.html
Copyright © 2011-2022 走看看