Requirements:
- There are three levels of menu options
- On each level menu you can go to the next menu, return to the previous level menu, and exit
Code:
1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 #author:james Tao4 5Data={6 'Beijing':{7 'changping':{8 'Shahe':['Oldboy','Test'],9 'Tin Tong Court':['Chain Home Property','I love my family .']Ten }, One 'Chaoyang':{ A 'Wangjing':['Mercedes','mo Mo'], - 'Guomao':{'CCIC','HP'}, - 'Dong Zhi men':{'Advent','fetion'} the }, - 'Haidian':{} - }, - 'Shandong':{ + 'Texas':{}, - 'Qingdao':{}, + 'Jinan':{} A }, at 'Guangdong':{ - 'Dongguan':{}, - 'Changshu':{}, - 'Foshan':{} - } - } in -flag=True to + whileflag: - the forIinchData: * Print(i) $First_choice=input ('Select Enter Next Level menu/Enter Q to exit:')Panax Notoginseng - #go to the first level menu the ifFirst_choiceinchData: + A whileflag: the + forJinchData[first_choice]: - Print('\ t', J) $Second_choice=input ('Select Enter Next Level menu/Enter R to return to previous/input Q exit:') $ - #go to the second level menu - ifSecond_choiceinchData[first_choice]: the whileflag: - Wuyi forZinchData[first_choice][second_choice]: the Print('\t\t', Z) -Third_choice=input ('Select Enter Next Level menu/Enter R to return to previous/input Q exit:') Wu - #go to the third level menu About ifThird_choiceinchData[first_choice][second_choice]: $ whileflag: - - forKinchData[first_choice][second_choice][third_choice]: - Print('\t\t\t', K) AFourth_choice=input ('last layer, enter R to return to the previous level/input Q exit:') + the #whether to return to the third level or exit - iffourth_choice=='R': $ Break the eliffourth_choice=='Q': theflag=False the the #whether to return to the second level or exit - ifthird_choice=='R': in Break the elifThird_choice = ='Q': theFlag =False About the #whether to return to the first level or exit the ifsecond_choice=='R': the Break + elifThird_choice = ='Q': -Flag =False the Bayi #whether to exit the iffirst_choice=='Q': the Break
Using dictionaries to write menu programs