python字典实现三级菜单

 1 #_author_: edison
 2 #date: 2017/8/10
 3 china = {
 4     '广东':{
 5         '广州':{'海珠':'红烧螃蟹','越秀':'蚝蛎煎蛋'},
 6         '深圳':{'南山':'油焖大虾','罗湖':'小炒肉'},
 7         '珠海':{'金湾':'清蒸螃蟹','斗门':'火爆腰花'},
 8     },
 9     '四川':{
10         '成都':{'双流':'双流老妈兔头','郫县':'七婆串串'},
11         '绵阳':{'三台':'三台丰水梨','梓州':'梓州板鸭'},
12         '南充':{'西充':'狮子糕','蓬安':'姚麻花'}
13     },
14     '云南':{
15         '丽江':{'永胜':'板鸭','华坪':'青椒肉丝'},
16         '昆明':{'盘龙':'干锅','五华':'火锅'},
17         '玉溪':{'红塔':'红塔山','江川':'云烟'}
18     }
19 }
20 
21 
22 back_flag = False       #返回标志位
23 quit_flag = False       #退出标志位
24 while not back_flag and not quit_flag:
25     for key in china:
26         print(key)
27     choice = input('输入你喜欢的省会:').strip()      #strip() 方法用于移除字符串头尾指定的字符(默认为空格)
28     if choice in china:
29         while not back_flag and not quit_flag:       #让程序停在第二层
30             for key2 in china[choice]:
31                 print(key2)
32             choice2 = input('输入你喜欢的城市(b返回上一级,q退出):').strip()
33             if choice2 == 'b':
34                 back_flag = True
35             if choice2 == 'q':
36                 quit_flag = True
37             if choice2 in china[choice]:
38                 while not back_flag and not quit_flag:
39                     for key3 in china[choice][choice2]:
40                         print(key3)
41                     choice3 = input('输入你喜欢的区县(b返回上一级,q退出):').strip()
42                     if choice3 == 'b':
43                         back_flag = True
44                     if choice3 == 'q':
45                         quit_flag = True
46                     if choice3 in china[choice][choice2]:
47                         while not back_flag and not quit_flag:
48                             for key4 in china[choice][choice2][choice3]:
49                                 print(key4)
50                             choice4 = input('(b返回上一级,q退出):').strip()
51                             if choice4 == 'b':
52                                 back_flag = True
53                             if choice4 == 'q':
54                                 quit_flag = True
55                         else:
56                             back_flag = False
57                 else:
58                     back_flag = False
59         else:
60             back_flag = False

 

转载于:https://www.cnblogs.com/stejovbes/p/7345336.html

你可能感兴趣的:(python字典实现三级菜单)