zoukankan      html  css  js  c++  java
  • 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)
    

    运行结果:

  • 相关阅读:
    java学习day08--面向对象--继承+方法重写+static关键字
    java学习day07--面向对象--封装+this关键字+构造器
    java学习day06-面向对象--类和对象
    依赖管理
    NSQ消息队列
    logger包
    time包
    fmt包
    Go_Protobu
    Go_性能优化
  • 原文地址:https://www.cnblogs.com/klvchen/p/8646466.html
Copyright © 2011-2022 走看看