#coding: utf-8dict={' Beijing ': {' haidingqu ': [' Qinghe ', ' Keji '], ' chaoyangqu ': [' Q ', ' W ']}, ' Shandong ': {' liaochen ': [' Chiping ', ' Yanggu '], ' Dezhou ': [' e ', ' R ']}}for index,i in Enumerate (dict): #首先循环显示一级菜单 print index,i, print ' Exit Q ' #后补上的退出功能, added to the dictionary to show the trouble, simply first display, in the submenu of the exit function through the individual variable assignment implementation exit, A= '!q ' #退出变量赋值, value you casually up, as long as you understand while a!= ' Q ': #判断是否键入了退出字符 title=raw_input (' Enter the city name you want to enter: ') if Title.isalpha (): #判断输入的是否是纯字符串 if Dict.has_ Key (title): #判断键入的值在字典中 for index,i in enumerate (Dict[title]): print index,i #显示输入城市的详细信息 Dict=dict[title] #当前所在菜单及子菜单赋值 elif title== ' q ': #判断键入的是不是退出字符 a= ' q ' #赋值, terminating the loop Else: print ' input is wrong, please re-enter! ' elif title== ' q ' : #判断键入的是不是退出字符 a= ' q ' #赋值, terminating the loop else: print ' exited '
python--Implementation of Level three menu selection (original)