zoukankan      html  css  js  c++  java
  • python-三级菜单

    第一种方法:

    # _Author:huang
    # date: 2017/11/29

    menu = {
    '河南': {
    '郑州': {
    '金水区': {
    '东风路': {},
    '北三环': {},
    '明基路': {}
    },
    },
    '南阳': {
    '淅川县': {},
    '西峡县': {},
    '方程': {},
    },
    },
    '江苏': {
    '南京': {
    '鼓楼': {},
    '栖霞区': {},
    '下关区': {}
    },
    '苏州': {
    '城区': {},
    '苏州园林': {}
    }
    },
    '北京': {
    '昌平区': {
    'sohu': {},
    'sogo': {}
    },
    '昭阳区': {
    '360': {},
    'google': {}
    }
    }
    }

    current_layer = menu

    parent_layers = []

    while True:
    for key in current_layer:
    print(key)
    choice = input(">>>:").strip()
    if len(choice) == 0:
    continue
    if choice in current_layer:
    parent_layers.append(current_layer)
    current_layer = current_layer[choice]

    elif choice == 'b':
    if parent_layers:
    current_layer = parent_layers.pop()
    else:
    print("无此地名")




    第二种方法:
    # _Author:huang
    # date: 2017/11/28

    menu = {
    '北京': {
    '朝阳': {
    '国贸': {
    'CICC': {},
    'HP': {},
    '渣打一行': {}
    }
    },
    '望京': {
    '陌陌': {},
    '奔驰': {},
    '360': {}
    },
    '三里屯': {
    '优衣库': {},
    'apple': {}
    },
    '昌平': {
    '天通苑': {
    '链家': {},
    '我爱我家': {}
    },
    '回龙观': {},
    },
    '海淀': {
    '五道口': {
    '谷歌': {},
    '网易': {},
    'sohu': {},
    'sogo': {},
    '快手': {},
    },
    '中关村': {
    'youku': {},
    'Iqiyi': {},
    "汽车之家": {},
    "新东方": {},
    'QQ': {}
    }
    }
    },
    '上海': {
    '浦东': {
    '陆家嘴': {
    'CICC': {},
    '高盛': {},
    '摩根': {}
    },
    '外滩': {},
    },
    '闵行': {},
    '静安': {}
    },

    '山东': {
    '济南': {},
    '青岛': {},
    '德州': {
    '乐陵': {
    '丁坞镇': {},
    '城区': {}
    },
    '平原县': {}
    }
    }
    }
    back_flag = False
    exit_flag = False
    while not back_flag and not exit_flag:
    for key in menu:
    print(key) # 打印第一层代码
    choice = input(">>:").strip()
    if choice == 'b':
    back_flag = True
    if choice == 'q':
    exit_flag = True
    if choice in menu: # 判断是否在第一层
    while not back_flag and not exit_flag: #让程序停在第二层
    for key2 in menu[choice]:
    print(key2) # 打印第二层
    choice2 = input("2>>:").strip()
    if choice2 == 'b':
    back_flag = True
    if choice2 == 'q':
    exit_flag = True
    if choice2 in menu[choice]:
    for key3 in menu[choice][choice2]:
    print(key3)
    choice3 = input("3>>:").strip()
    if choice3 == 'b':
    back_flag = True
    if choice3 == 'q':
    exit_flag = True
    if choice3 in menu[choice][choice2]:
    while not back_flag and not exit_flag:
    for key4 in menu[choice][choice2][choice3]:
    print(key4)
    choice4 = input("4>>:").strip()
    print("last lever")
    if choice4 == 'b':
    back_flag = True
    if choice4 == 'q':
    exit_flag = True
    else:
    back_flag = False

    else:
    back_flag = False

    else:
    back_flag = False

  • 相关阅读:
    51 Nod 1086 多重背包问题(单调队列优化)
    51 Nod 1086 多重背包问题(二进制优化)
    51 Nod 1085 01背包问题
    poj 2559 Largest Rectangle(单调栈)
    51 Nod 1089 最长回文子串(Manacher算法)
    51 Nod N的阶乘的长度 (斯特林近似)
    51 Nod 1134 最长递增子序列(经典问题回顾)
    51 Nod 1020 逆序排列
    PCA-主成分分析(Principal components analysis)
    Python中cPickle
  • 原文地址:https://www.cnblogs.com/1510152012huang/p/7922158.html
Copyright © 2011-2022 走看看