您好,登錄后才能下訂單哦!
本文實(shí)例講述了Python3.5實(shí)現(xiàn)的三級菜單功能。分享給大家供大家參考,具體如下:
程序:三級菜單
要求:
1. 打印省、市、縣三級菜單
2. 可返回上一級
3. 可隨時退出程序
具體代碼:
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author:ZhengzhengLiu Province_Data = { "北京市":{ "朝陽區(qū)":{ "南磨房地區(qū)":["東郊社區(qū)","平樂園社區(qū)"], "高碑店地區(qū)":["興隆家園社區(qū)","大黃莊社區(qū)"], "將臺地區(qū)":["麗都社區(qū)","房里苑社區(qū)"] }, "海淀區(qū)":{ "萬壽路街道":["",""], "羊坊店街道":["",""], "八里莊街道":["",""] }, "懷柔區(qū)":{ "懷柔鎮(zhèn)":["",""], "雁棲鎮(zhèn)":["",""], "城廟鎮(zhèn)":["",""] } }, "天津市":{ "和平區(qū)":{ "勸業(yè)場街道":["",""], "小白樓街道":["",""], "五大道街道":["",""] }, "南開區(qū)":{ "華苑街道":["",""], "長虹街道":["",""], "鼓樓街道":["",""] }, "河西區(qū)":{ "桃園街道":["",""], "馬場街道":["",""], "大營門街道":["",""] } }, "河北省":{ "石家莊市":{ "長安區(qū)":["",""], "橋西區(qū)":["",""], "新華區(qū)":["",""] }, "廊坊市":{ "安次區(qū)":["",""], "廣陽區(qū)":["",""], "西小區(qū)":["",""] }, "唐山市":{ "路南區(qū)":["",""], "路北區(qū)":["",""], "古冶區(qū)":["",""] } }, "山東省":{ "青島市":{ "市南區(qū)":["",""], "市北區(qū)":["",""], "即墨市":["",""] }, "濟(jì)南市":{ "歷下區(qū)":["",""], "市中區(qū)":["",""], "槐蔭區(qū)":["",""] }, "煙臺市":{ "福山區(qū)":["",""], "萊山區(qū)":["",""], "牟平區(qū)":["",""] } } } exit_flag = False #退出標(biāo)志符 while not exit_flag: for i in Province_Data: print(i) user_choice = input("Please choose the province...") if user_choice in Province_Data: while not exit_flag: for j in Province_Data[user_choice]: print('\t',j) user_choice1 = input("Please choose the city...") if user_choice1 in Province_Data[user_choice]: while not exit_flag: for k in Province_Data[user_choice][user_choice1]: print('\t\t',k) user_choice2 = input("Please choose the communitiy...") if user_choice2 in Province_Data[user_choice][user_choice1]: while not exit_flag: for l in Province_Data[user_choice][user_choice1][user_choice2]: print('\t\t\t',l) user_choice3 = input("The last choose,please enter 'b' to back...") if user_choice3 == 'b': break elif user_choice3 == 'q': exit_flag = True if user_choice2 == 'b': break elif user_choice2 == 'q': exit_flag = True if user_choice1 == 'b': break elif user_choice1 == 'q': exit_flag = True #運(yùn)行結(jié)果: ''' 山東省 河北省 天津市 北京市 Please choose the province...北京市 朝陽區(qū) 懷柔區(qū) 海淀區(qū) Please choose the city...朝陽區(qū) 南磨房地區(qū) 將臺地區(qū) 高碑店地區(qū) Please choose the communitiy...將臺地區(qū) 麗都社區(qū) 房里苑社區(qū) The last choose,please enter 'b' to back...b 南磨房地區(qū) 將臺地區(qū) 高碑店地區(qū) Please choose the communitiy...b 朝陽區(qū) 懷柔區(qū) 海淀區(qū) Please choose the city...b 山東省 河北省 天津市 北京市 Please choose the province...北京市 朝陽區(qū) 懷柔區(qū) 海淀區(qū) Please choose the city...q Process finished with exit code 0 '''
PS:這里再為大家推薦幾款比較實(shí)用的json在線工具供大家參考使用:
在線JSON代碼檢驗(yàn)、檢驗(yàn)、美化、格式化工具:
http://tools.jb51.net/code/json
JSON在線格式化工具:
http://tools.jb51.net/code/jsonformat
在線XML/JSON互相轉(zhuǎn)換工具:
http://tools.jb51.net/code/xmljson
json代碼在線格式化/美化/壓縮/編輯/轉(zhuǎn)換工具:
http://tools.jb51.net/code/jsoncodeformat
在線json壓縮/轉(zhuǎn)義工具:
http://tools.jb51.net/code/json_yasuo_trans
更多Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python操作json技巧總結(jié)》、《Python編碼操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計(jì)有所幫助。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。