• python 三级菜单 的另1种实现方法


    menu = {
     "华南":{
      "广东":["广州市","佛山市","深圳市","东莞市"],
    
      "广西":["南宁市","柳州市","桂林市","北海市"],
    
    
      "海南":["海口市","三亚市","三沙市","儋州市"]
    
     },
     "华东":{
      "上海":["黄浦区","卢湾区","徐汇区","长宁区","普陀区"],
    
      "安徽":["合肥市","芜湖市","淮南市","马鞍山市"],
    
      "江苏":["南京市","无锡市","徐州市","常州市","苏州市"]
    
     },
     "华北":{
      "北京":["东城区","西城区","朝阳区","丰台区","石景山区","海淀区"],
    
      "山西":["太原市","大同市","阳泉市","长治市"],
    
      "河北":["石家庄市","唐山市","秦皇岛市","邢台市"]
    
     },
     "华中":{
      "湖北":["武汉市","黄石市","十堰市","十堰市"],
    
      "河南":["郑州市","开封市","洛阳市","平顶山市"],
    
      "湖南":["长沙市","株洲市","衡阳市","邵阳市"]
    
     },
     "西南":{
      "重庆":["万州区","涪陵区","渝中区","大渡口区"],
      "四川":["成都市","自贡市","攀枝花市","德阳市"],
      "贵州":["贵阳市","六盘水市","遵义市","安顺市"],
    
    
     },
     "特别行政区":{
      "香港":["屯门","弯仔","北角","西贡"],
      "澳门":["花地玛堂区","圣安多尼堂区","大堂区","望德堂区"],
    
     },
    
    
    }
    last = [menu]
    now = menu
    while True:
        for key in now:
            print(key)
        choice = input('>>>:').strip()
        if choice == 'q':
            break
        if choice == 'b':
            now = last[-1]
            last.pop()
        if choice in now:
            last.append(now)
            now = now[choice]

    主要实现方法:

    将目前菜单添加到menu里面,然后b返回时再从添加的menu里面把菜单提取出来。

  • 相关阅读:
    Codeforces Round #719 (Div. 3) 题解
    Codeforces Global Round 14 A~F题解
    AtCoder Beginner Contest 199 题解
    Codeforces Round #716 (Div. 2) A~D 题解
    Codeforces Round #713 (Div. 3) 题解
    Codeforces Round #712 (Div. 2) A~E 题解
    CodeCraft-21 and Codeforces Round #711 (Div. 2) A~E 题解
    CF839 D 莫比乌斯反演
    java存大数和高精度浮点数(BigInteger与BigDecimal)
    java科学计算常用方法(Math)
  • 原文地址:https://www.cnblogs.com/qunxiadexiaoxiangjiao/p/8251525.html
Copyright © 2020-2023  润新知