Python 练习:三级菜单选择城市

本文介绍了一个简单的Python程序,该程序可以查询中国的省份、城市及区县信息。通过输入省份名称,程序将显示该省份下的所有城市,并进一步提供每个城市的区县列表。文章包含完整的代码实现及运行结果。
info = {
    'GuangDong':{
        'GuangZhou': ['TianHe', 'HaiZhu'],
        'MaoMing': ['MaoNan', 'DianBai']},
    'ShanDong': {
        'JiNan': ['ShiZhong', 'LiXia'],
        'QingDao': ['ShiNan', 'ShiBei']
    },
    'GuangXi': {
        'NanNin': ['WuNing', 'LongAn'],
        'GuiLing': ['YangSuo', 'QuanZhou']
    }
}

flag = True

while flag:
    print(''.center(50, '#'))
    for p in info.keys():
        print("省份:", p)
    province = input("Please input the province: [e : exit]")
    if province == 'e':
        break
    if (province in list(info.keys())) == False:
        print("You need to input right province!")
        continue
    while True:
        print(''.center(50, '#'))
        for c in info[province].keys():
            print("城市: ", c)
        city = input("Please input the city: [q: return; e: exit]")
        if city == 'q':
            break
        if city == 'e':
            flag = False
            break
        if (city in list(info[province].keys())) == False:
            print("You need to input right city!")
            continue
        for k in info[province][city]:
            print("区县: ", k)

运行结果:
1334255-20180325202131263-1140347924.png

转载于:https://www.cnblogs.com/klvchen/p/8646466.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值