第一天作业二 三级菜单的实现
![](https://images2015.cnblogs.com/blog/900310/201610/900310-20161019143954217-1760849300.png)
这个作业花了一定的时间,主要是卡在循环时显示不同的问题。
#!/usr/bin/env python # -*-conding:utf-8-** # __Author__:'liudong' stats={ "1.北京":{ "1.海淀区":["中关村","西三旗","学院路"], "2.东城区":["安定门","朝阳门","建国门"], "3.丰台区":["右安门","东高地","卢沟桥"] }, "2.天津":{ "1.和平区":["南市","滨江道","南京路"], "2.河西区":["小海地","西南楼","友谊路"], "3.河东区":["中山门","万新村","津滨大道"] }, "3.广东省":{ "1.广州市":["白云区","天河区","越秀区"], "2.佛山市":["南海区","三水区","高明区"], "3.深圳市":["福田区","罗湖区","南山区"] }, "4.浙江省":{ "1.宁波市":["海曙区","江东区","江北区"], "2.杭州市":["上城区","下城区","江干区"], "3.温州市":["鹿城区","龙湾区","洞头区"] } } def Display_stats(): #显示省市主界面 print ("-------------------------------------------------") print ("重点省市查询:") print ("-------------------------------------------------") for i in stats.keys(): #遍历行政省级地区键值 print(i) print("---------------------------------------------------") print('Q[q] for exit') def display_Beijing(): #显示北京的信息 print('beijing provinces list') print('---------------------------------------------------') for i in stats['1.北京'].keys(): print(i) print('---------------------------------------------------') print('B[b]:BACK,Q[q]:EXIT') def display_Tianjin(): print('Tianjin provinces list') print('---------------------------------------------------') for i in stats['2.天津'].keys(): print(i) print('---------------------------------------------------') print('B[b]:BACK,Q[q]:EXIT') def display_Guangdong(): print('GuangDong provinces list') print('---------------------------------------------------') for i in stats['3.广东省'].keys(): print(i) print('---------------------------------------------------') print('B[b]:BACK,Q[q]:EXIT') def display_Zhejiang(): print('Zhejiang provinces list') print('---------------------------------------------------') for i in stats['4.浙江省'].keys(): print(i) print('---------------------------------------------------') print('B[b]:BACK,Q[q]:EXIT') if __name__ == '__main__': Display_stats() while True: stats_choice=input('Please press number 1-4 for stats information:') if stats_choice == 'B' or stats_choice == 'b': Display_stats() if stats_choice == 'Q' or stats_choice=='q': exit() else: if stats_choice == "1": display_Beijing() province_choice=input('Press number for province information:') if province_choice =='q' or province_choice == 'Q': exit() if province_choice == 'b' or province_choice == 'B': display_Beijing() if province_choice == '1': print('---------------------------------------------------') for i in stats['1.北京']["1.海淀区"]: print(i) print('---------------------------------------------------') quit_back_choice=input('B[b]:BACK,Q[q]:EXIT]') if quit_back_choice == 'B' or quit_back_choice == 'b': display_Beijing() if quit_back_choice == 'q' or quit_back_choice == 'Q': exit() if province_choice == '2': print('---------------------------------------------------') for i in stats['1.北京']["2.东城区"]: print(i) print('---------------------------------------------------') quit_back_choice=input('B[b]:BACK,Q[q]:EXIT]') if quit_back_choice == 'B' or quit_back_choice == 'b': display_Beijing() if quit_back_choice == 'q' or quit_back_choice == 'Q': exit() if province_choice == '3': print('---------------------------------------------------') for i in stats['1.北京']["3.丰台区"]: print(i) print('---------------------------------------------------') quit_back_choice=input('B[b]:BACK,Q[q]:EXIT]') if quit_back_choice == 'B' or quit_back_choice == 'b': display_Beijing() if quit_back_choice == 'q' or quit_back_choice == 'Q': exit() if stats_choice == "2": display_Tianjin() province_choice=input('Press number for provice information:') if province_choice =='q' or province_choice == 'Q': exit() if province_choice == 'b' or province_choice == 'B': Display_stats() if province_choice == '1': print('---------------------------------------------------') for i in stats['2.天津']["1.和平区"]: print(i) print('---------------------------------------------------') quit_back_choice=input('B[b]:BACK,Q[q]:EXIT]') if quit_back_choice == 'B' or quit_back_choice == 'b': display_Tianjin() if quit_back_choice == 'q' or quit_back_choice == 'Q': exit() if province_choice == '2': print('---------------------------------------------------') for i in stats['2.天津']["2.河西区"]: print(i) print('---------------------------------------------------') quit_back_choice=input('B[b]:BACK,Q[q]:EXIT]') if quit_back_choice == 'B' or quit_back_choice == 'b': display_Tianjin() if quit_back_choice == 'q' or quit_back_choice == 'Q': exit() if province_choice == '3': print('---------------------------------------------------') for i in stats['2.天津']["3.河东区"]: print(i) print('---------------------------------------------------') quit_back_choice=input('B[b]:BACK,Q[q]:EXIT]') if quit_back_choice == 'B' or quit_back_choice == 'b': display_Tianjin() if quit_back_choice == 'q' or quit_back_choice == 'Q': exit() if stats_choice == "3": display_Guangdong() province_choice=input('Press number for provice information:') if province_choice =='q' or province_choice == 'Q': exit() if province_choice == 'b' or province_choice == 'B': Display_stats() if province_choice == '1': print('---------------------------------------------------') for i in stats['3.广东省']["1.广州市"]: print(i) print('---------------------------------------------------') quit_back_choice=input('B[b]:BACK,Q[q]:EXIT]') if quit_back_choice == 'B' or quit_back_choice == 'b': display_Guangdong() if quit_back_choice == 'q' or quit_back_choice == 'Q': exit() if province_choice == '2': print('---------------------------------------------------') for i in stats['3.广东省']["2.佛山市"]: print(i) print('---------------------------------------------------') quit_back_choice=input('B[b]:BACK,Q[q]:EXIT]') if quit_back_choice == 'B' or quit_back_choice == 'b': display_Guangdong() if quit_back_choice == 'q' or quit_back_choice == 'Q': exit() if province_choice == '3': print('---------------------------------------------------') for i in stats['3.广东省']["3.深圳市"]: print(i) print('---------------------------------------------------') quit_back_choice=input('B[b]:BACK,Q[q]:EXIT]') if quit_back_choice == 'B' or quit_back_choice == 'b': display_Guangdong() if quit_back_choice == 'q' or quit_back_choice == 'Q': exit() if stats_choice == "4": display_Zhejiang() province_choice=input('Press number for provice information:') if province_choice =='q' or province_choice == 'Q': exit() if province_choice == 'b' or province_choice == 'B': Display_stats() if province_choice == '1': print('---------------------------------------------------') for i in stats['4.浙江省']["1.宁波市"]: print(i) print('---------------------------------------------------') quit_back_choice=input('B[b]:BACK,Q[q]:EXIT]') if quit_back_choice == 'B' or quit_back_choice == 'b': display_Zhejiang() if quit_back_choice == 'q' or quit_back_choice == 'Q': exit() if province_choice == '2': print('---------------------------------------------------') for i in stats['4.浙江省']["2.杭州市"]: print(i) print('---------------------------------------------------') quit_back_choice=input('B[b]:BACK,Q[q]:EXIT]') if quit_back_choice == 'B' or quit_back_choice == 'b': display_Zhejiang() if quit_back_choice == 'q' or quit_back_choice == 'Q': exit() if province_choice == '3': print('---------------------------------------------------') for i in stats['4.浙江省']["3.温州市"]: print(i) print('---------------------------------------------------') quit_back_choice=input('B[b]:BACK,Q[q]:EXIT]') if quit_back_choice == 'B' or quit_back_choice == 'b': display_Zhejiang() if quit_back_choice == 'q' or quit_back_choice == 'Q': exit()
“我们知道,世界上存在着已知的已知事物,也就是说有些事情我们知道自己知道,而我们也知道世上存在着被人所知的不明事物,这就是说有些事情我们知道自己不知道。同时,世上还存在着我们不知道的不明事物,也就是说我们不知道自己不知道。”