Python3.5——三级菜单示例程序

来源:互联网 发布:win7 网络电缆被拔出 编辑:程序博客网 时间:2024/05/20 20:04

#!/usr/bin/env python# -*- coding:utf-8 -*-# Author:ZhengzhengLiuProvince_Data = {    "北京市":{        "朝阳区":{            "南磨房地区":["东郊社区","平乐园社区"],            "高碑店地区":["兴隆家园社区","大黄庄社区"],            "将台地区":["丽都社区","房里苑社区"]        },        "海淀区":{            "万寿路街道":["",""],            "羊坊店街道":["",""],            "八里庄街道":["",""]        },        "怀柔区":{            "怀柔镇":["",""],            "雁栖镇":["",""],            "城庙镇":["",""]        }    },    "天津市":{        "和平区":{            "劝业场街道":["",""],            "小白楼街道":["",""],            "五大道街道":["",""]        },        "南开区":{            "华苑街道":["",""],            "长虹街道":["",""],            "鼓楼街道":["",""]        },        "河西区":{            "桃园街道":["",""],            "马场街道":["",""],            "大营门街道":["",""]        }    },    "河北省":{        "石家庄市":{            "长安区":["",""],            "桥西区":["",""],            "新华区":["",""]        },        "廊坊市":{            "安次区":["",""],            "广阳区":["",""],            "西小区":["",""]        },        "唐山市":{            "路南区":["",""],            "路北区":["",""],            "古冶区":["",""]        }    },    "山东省":{        "青岛市":{            "市南区":["",""],            "市北区":["",""],            "即墨市":["",""]        },        "济南市":{            "历下区":["",""],            "市中区":["",""],            "槐荫区":["",""]        },        "烟台市":{            "福山区":["",""],            "莱山区":["",""],            "牟平区":["",""]        }    }}exit_flag = False   #退出标志符while not exit_flag:    for i in Province_Data:        print(i)    user_choice = input("Please choose the province...")    if user_choice in Province_Data:        while not exit_flag:            for j in Province_Data[user_choice]:                print('\t',j)            user_choice1 = input("Please choose the city...")            if user_choice1 in Province_Data[user_choice]:                while not exit_flag:                    for k in Province_Data[user_choice][user_choice1]:                        print('\t\t',k)                    user_choice2 = input("Please choose the communitiy...")                    if user_choice2 in Province_Data[user_choice][user_choice1]:                        while not exit_flag:                            for l in Province_Data[user_choice][user_choice1][user_choice2]:                                print('\t\t\t',l)                            user_choice3 = input("The last choose,please enter 'b' to back...")                            if user_choice3 == 'b':                                break                            elif user_choice3 == 'q':                                exit_flag = True                    if user_choice2 == 'b':                        break                    elif user_choice2 == 'q':                        exit_flag = True            if user_choice1 == 'b':                break            elif user_choice1 == 'q':                exit_flag = True#运行结果:'''山东省河北省天津市北京市Please choose the province...北京市 朝阳区 怀柔区 海淀区Please choose the city...朝阳区 南磨房地区 将台地区 高碑店地区Please choose the communitiy...将台地区 丽都社区 房里苑社区The last choose,please enter 'b' to back...b 南磨房地区 将台地区 高碑店地区Please choose the communitiy...b 朝阳区 怀柔区 海淀区Please choose the city...b山东省河北省天津市北京市Please choose the province...北京市 朝阳区 怀柔区 海淀区Please choose the city...qProcess finished with exit code 0'''

原创粉丝点击