Python 基礎 - Day 1 Assignment - Three tier menu 三級菜單

來源:互聯網
上載者:User

標籤:bsp   中關村   pen   class   pass   exit   soho   google   sam   

作業要求

1. 運行程式輸出第一級菜單

2. 選擇一級菜單某項,輸出二級菜單,同理輸出三級菜單

3. 菜單資料儲存在檔案中

4. 讓使用者選擇是否要退出

5. 有返回上一級菜單的功能

評分標準:

用多層嵌套while迴圈的方式完成作業2,85分

只用一層迴圈完成作業2,100分

SAMPLE 1 
data = {    ‘北京‘: {        ‘海澱‘: {            ‘五道口‘: {                ‘soho‘: {},                ‘網易‘: {},                ‘Google‘: {},            },            ‘中關村‘: {                ‘愛奇藝‘: {},                ‘汽車之家‘: {},                ‘youku‘: {},            },            ‘上地‘: {                ‘baidu‘: {},            },        },        ‘昌平‘: {            ‘沙河‘: {                ‘oldboy‘: {},                ‘北航‘: {},            },            ‘天通苑‘: {},            ‘回龍觀‘: {},        },        ‘朝陽‘: {},        ‘東城‘: {},    },    ‘上海‘: {        "黃浦": {            ‘人民廣場‘: {                ‘炸雞店‘: {},            },        },        ‘閘北‘: {            ‘火車站‘: {                ‘攜程‘: {},            },        },        ‘浦東‘: {},    },    ‘山東‘: {},}exit_flag = Falsewhile not exit_flag:    for i in data:        print(i)   # 進入死迴圈    choice = input("your option >>>:")    if choice in data:        while not exit_flag:            for j in data[choice]:                print("\t", j)            choice2 = input(‘your 2nd option >>>:‘)            while not exit_flag:                for k in data[choice][choice2]:                    print(‘\t\t‘, k)                choice3 = input(‘your 3rd option >>>:‘)                if choice3 in data[choice][choice2]:                    for l in data[choice][choice2][choice3]:                        print(‘\t\t‘, l)                    choice4 = input("final, please input b for exit")                    if choice4 == ‘b‘:                        pass  # pass == 啥都不做,必須寫否則報錯。作為預留位置                    elif choice4 == "q":                        exit_flag = True                if choice3 == ‘b‘:                    break                elif choice3 == "q":                    exit_flag = True            if choice2 == ‘b‘:                break            elif choice2 == "q":                exit_flag = True
View Code

 

 

Python 基礎 - Day 1 Assignment - Three tier menu 三級菜單

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.