python_入門_三級菜單,

來源:互聯網
上載者:User

python_入門_三級菜單,


'''程式:三級菜單
要求:
1、列印省、市、縣三級菜單
2、可返回上一級
3、可隨時退出程式
'''
 1 # -*- coding: utf-8 -*- 2 # __author__ = 'qi' 3 prov_city_conty ={"北京": 4                     {"東城區","西城區","崇文區","宣武區","朝陽區","丰台區","石景山區","海澱區","順義區"}, 5                 "上海": 6                     {"黃埔區","盧灣區","徐匯區","長寧區","靜安區","普陀區","閘北區","楊浦區","閔行區"}, 7                 "河北": 8                     { 9                     "石家莊市":10                                 {"長安區","橋東區","橋西區","新華區","井陘礦區","裕華區"},11                     "唐山市":12                                 {"路南區","路北區","古冶區","開平區","豐潤區","灤縣"}13                     },14                 "江蘇":15                     {16                     "南京市":17                                 {"玄武區","白下區","秦淮區","建鄴區","鼓樓區","下關區","浦口區"},18                     "蘇州市":19                                 {"滄浪區","平江區","金閶區","吳中區","相城區","常熟市"}20                     }21                 }22 while True:23     print ("-----列印省菜單------")24     for index,prov in enumerate(prov_city_conty,1):25         print index, prov26     choice_p_menu = raw_input("please select province number[quit:q]:")27     if choice_p_menu.isdigit():28         choice_p_menu = int(choice_p_menu)29         if choice_p_menu>0 and choice_p_menu<len(prov_city_conty):30             prov_name_list = prov_city_conty.keys()31             prov_name = prov_name_list[choice_p_menu-1]32             while True:33                 print ("-----"+prov_name+"------")34                 for index,city in enumerate(prov_city_conty[prov_name],1):35                     print index,city36                 if prov_name not in ["北京","上海"]:37                     choice_city_menu = raw_input("please select city number[quit:q]|[return:r]:")38                     if choice_city_menu.isdigit():39                         choice_city_menu = int(choice_city_menu)40                         if choice_city_menu>0 and choice_city_menu<len(prov_city_conty[prov_name]):41                             city_name_list = prov_city_conty[prov_name].keys()42                             city_name = city_name_list[choice_city_menu-1]43                             while True:44                                 print ("-----"+city_name+"------")45                                 for county in prov_city_conty[prov_name][city_name]:46                                     print county47                                 choice_q_r_menu = raw_input("please select [quit:q]|[return:r]:")48                                 if choice_q_r_menu == "q":49                                     exit()50                                 elif choice_q_r_menu == "r":51                                     break52                                 else:53                                     print("your input code %s is not exist!" %choice_q_r_menu)54                                     continue55                         else:56                             print ("city code %s is not exist!" %choice_city_menu)57                             continue58                     elif choice_city_menu == "q":59                         exit()60                     elif choice_city_menu == "r":61                         break62                 else:63                     choice_q_r_menu = raw_input("please select [quit:q]|[return:r]:")64                     if choice_q_r_menu == "q":65                         exit()66                     elif choice_q_r_menu == "r":67                         break68                     else:69                         print("your input code %s is not exist!" %choice_q_r_menu)70                         continue71         else:72             print ("province code %s is not exist!" %choice_p_menu)73     elif choice_p_menu == "q":74         break

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.