04-python3.5-模拟三级菜单-省-县-区域--01
1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 #Author:XZ 4 5 data = { 6 '北京':{ 7 "昌平":{ 8 "沙河":["Oldboy","Test"], 9 "天通苑":["链家地产","我爱我家"], 10 "回龙观":["北郊农场","天鸿集团"], 11 }, 12 "朝阳":{ 13 "望京":["奔驰","陌陌"], 14 "国贸":["CICC","HP"], 15 "东直门":["Advent","飞信"], 16 }, 17 "海淀":{ 18 "西三旗":["清景园","清缘里"], 19 "中关村":["清华大学","北京大学"], 20 "五棵松":["310医院","名仕医院"], 21 }, 22 }, 23 '山东':{ 24 "德州":{}, 25 "青岛":{}, 26 "济南":{}, 27 }, 28 '广东':{ 29 "东莞":{}, 30 "常熟":{}, 31 "佛山":{}, 32 }, 33 } 34 exit_flag = False 35 while not exit_flag: 36 for states in data: 37 print(states) 38 user_choice_state = input("请输入选择的省份:>>>") 39 if user_choice_state in data: 40 while not exit_flag: 41 for districts in data[user_choice_state]: 42 print("\t",districts) 43 user_choice_district = input("请输入选择的区/县:>>>") 44 if user_choice_district in data[user_choice_state]: 45 while not exit_flag: 46 for areas in data[user_choice_state][user_choice_district]: 47 print("\t\t",areas) 48 user_choice_area = input("请输入选择的地段:>>>") 49 if user_choice_area in data[user_choice_state][user_choice_district]: 50 for units_list in data[user_choice_state][user_choice_district][user_choice_area]: 51 print("\t\t\t", units_list) 52 user_choice_return = input("当前已是末端,如需返回请输入b:>>>") 53 if user_choice_return == 'b': 54 pass 55 elif user_choice_return == 'q': 56 exit_flag = True 57 if user_choice_area == 'b': 58 break 59 elif user_choice_area == 'q': 60 exit_flag = True 61 if user_choice_district == 'b': 62 break 63 elif user_choice_district == 'q': 64 exit_flag = True