Python write Level 3 menu

Source: Internet
Author: User

Python write Level 3 menu

#-*-Coding: UTF-8-*-_ author _ = 'am _ mm_NO.1 'import rememu = {"Northeast": {"Jilin Province": {"Jilin City ": ['Jilin city 1', 'Jilin city 2'], "Changchun": ['changchun 1 ', 'changchun 2'],}, "Liaoning Province": {"Shenyang ": ['shenyang 1', 'shenyang 2', 'shenyang 3'], "Dalian": ['dalian 1', 'dalian 2'],},}, 'North China': {'hebei province ': {'langfang': ['langfang 1', 'langfang 2'], 'baoding ': ['baoding 1 ', 'baoding 2'] ,}, 'inner Mongolia ': {'hohhot': ['hohhot 1', 'hohhot 2', 'hohhot 3'], 'baotou ': ['baotou 1', 'baotou 2'] },},} flag = Truewhile flag: # global variable, set to jump out of the entire loop for I, v in enumerate (memu. keys (): # traverse the first dictionary print I, v # print the first key, value num_1 = raw_input ("Enter the first menu number and press q to exit :"). strip () # accept keyboard input if num_1 = 'q': flag = False break if num_1.isdigit (): num_1 = int (num_1) if num_1 <= len (memu ): key_1 = memu. keys () [num_1] while flag: for i1, v1 in enumerate (memu [key_1]): print i1, v1 num_2 = raw_input ("Enter the Level 2 menu number, press q to exit. B returns :"). strip () if num_2 = 'q': flag = False break if num_2 = 'B': break if num_2.isdigit (): num_2 = int (num_2) if num_2 <= len (memu [key_1]): key_2 = memu [key_1]. keys () [num_2] while flag: for i2, v2 in enumerate (memu [key_1] [key_2]): print i2, v2 num_3 = raw_input ("Enter the Level 3 menu number, press q to exit. B returns :"). strip () if num_3 = 'q': flag = False break if num_3 = 'B': break if num_3.isdigit (): num_3 = int (num_3) if num_3 <= len (memu [key_1] [key_2]): key_3 = memu [key_1] [key_2]. keys () [num_3] while flag: for i3, v3 in enumerate (memu [key_1] [key_2] [key_3]): print i3, v3 num_4 = raw_input ("Exit by q, B returns :"). strip () if num_4 = 'q': flag = False break if num_4 = 'B': break

 

Related Article

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.