Python Learning-Dictionary 1

Source: Internet
Author: User

The first time to write technical blog, but also just apply for success, so first thank the blog Park related staff. Development for many years, until this year began to learn python, accustomed to C, C + + data format, so the first is the Python data type in the dictionary attracted. Basic knowledge has been written by a lot of colleagues, I just through my study in a work problem to illustrate.

Title: Level Three Menu

Requirements:

1. Run the program output first level menu

2. Select a Level menu item, output level two menu, output level three menu similarly

3. Go back to the previous menu and the top menu

4. The menu data is saved in the file "

Implementation code:

#准备一个三级菜单
Menu_list = {"Gansu": {"Lanzhou": {"Chengguan District": {1: "Gansu Geological Museum", 2: "Earth Hall",                                           3: "Mineral Rock Hall"}, "Qilihe District": {1: "Lanzhou steles", 2: "Bei Xuan",                                         3: "Pavilion"}, "Xigu District": {1: "51 Mountain eco-tourist area",                               2: "Acacia", 3: "Metasequoia", 4: "Loquat"},                                         "Honggu District": {1: "Baidashan Park", 2: "Elephant skin drum",                      3: "Bronze Bell", 4: "Bauhinia Tree",}},                                         "Dunhuang": {"Shazhou Town": {"Dunhuang Mogao grottoes": "5A", "Mingsha Mountain-Crescent Spring Scenic Area": "4 A", "Sunshine Ruins": "4 A",}, "Suzhou Town": {"Gansu Dunhuang Yadan National Geopark": "4 A", "             White Horse Tower ":" 1 A "},               },}, "Ningxia": {"Zhongwei City": {"zhongning": {"Food": "Noodle",                                         "Attractions": "Doi Suthep", "specialty": "Wolfberry", "Zhongwei": {"Food": "Hinterland",                          "Attractions": "Shapotou", "specialty": "Sheepskin Raft",},                                         }, "Wuzhong": {"Litong District": {1: "Chai Yuen Village", 2: "Plum Orchard Village", 3: "Stone Buddha Village"}, "Qingtongxia": {1: "Liu Jian Tan cun", 2: "WA lu Gou                                          Village ", 3:" Er qiao Cun "}," Yanchi County ": {1:" Yang Cha cun ",                                          2: "Wu Jia Qiao Cun", 3: "Guo Jia Qiao Cun",                                 4: "Liujiawan Village",}, "Tongxin County": {1: "Shanshui gou Cun", 2: "Shimizu Gou Cun",         3: "Shan Village", 4: "Ma Jia Wan Village",},}, "Yinchuan ": {" Yinchuan ": {1:" Sea Pagoda ", 2:" Huaxia West movie City ", 3:" The Mosque of the satisfied household "                            , 4: "Grand Temple and Nan Guan Halal Mosque",}, "Xixia District": {"Scenic Area": "Xixia Mausoleum"},        },},} #一个死循环 so that it can be entered repeatedly until input q exits while True:index = 0 for I in Menu_list.keys ():        Print (str (index) + ":", i) Index + = 1 oper = str (input ("PROVINCE>:")) if Oper = = "Q": #判断是否退出 Exit () Elif oper not in Menu_list.keys (): #判断输入是否合规 print ("Input does not exist, please re-enter!") ") Else:one = Menu_list[oper] Print (" *************************************** ") while True: #进 Enter level two Menu index = 0 for i in One.keys (): Print (str (index) + ":", i) index            + = 1 oper = str (input ("CITY>:"))if oper = = "Q": #是否退出判断 exit () elif oper = = "B": #是否返回一级菜单 break Elif Oper not in One.keys (): Print ("Input does not exist, please re-enter!")                ") Else:two = One[oper] Print (" *************************************** ") While True: #进入三级菜单 index = 0 for i in Two.keys (): PR                    Int (str (index) + ":", i) Index + = 1 oper = str (input ("AREA>:"))                    if oper = = "Q": Exit () elif oper = = "B": Break Elif Oper not in Two.keys (): Print ("Input does not exist, please re-enter!") ") Else:print (Two[oper]) print (" ************************ ***************")

Python Learning-Dictionary 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.