Python 基礎 - Day 1 Assignment - Three tier menu 三級菜單
阿新 • • 發佈:2017-07-06
src for 退出 數據保存 ide aid b- python hide
作業要求
1. 運行程序輸出第一級菜單
2. 選擇一級菜單某項,輸出二級菜單,同理輸出三級菜單
3. 菜單數據保存在文件中
4. 讓用戶選擇是否要退出
5. 有返回上一級菜單的功能
評分標準:
用多層嵌套while循環的方式完成作業2,85分
只用一層循環完成作業2,100分
SAMPLE 1
data = { ‘北京‘: { ‘海澱‘: { ‘五道口‘: { ‘soho‘: {}, ‘網易‘: {}, ‘Google‘: {}, },View Code‘中關村‘: { ‘愛奇藝‘: {}, ‘汽車之家‘: {}, ‘youku‘: {}, }, ‘上地‘: { ‘baidu‘: {}, }, }, ‘昌平‘: { ‘沙河‘: { ‘oldboy‘: {}, ‘北航‘: {}, },‘天通苑‘: {}, ‘回龍觀‘: {}, }, ‘朝陽‘: {}, ‘東城‘: {}, }, ‘上海‘: { "黃浦": { ‘人民廣場‘: { ‘炸雞店‘: {}, }, }, ‘閘北‘: { ‘火車站‘: { ‘攜程‘: {}, }, }, ‘浦東‘: {}, },‘山東‘: {}, } exit_flag = False while 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
Python 基礎 - Day 1 Assignment - Three tier menu 三級菜單