# __*__ coding: utf-8 __*__ __author__ = "david.z" menu = { '北京':{ '海淀':{ '五道口':{ 'soho':{}, '网易':{}, 'google':{} }, '中关村':{ '爱奇艺':{}, '汽车之家':{}, 'youku':{}, }, '上地':{ '百度':{}, }, }, '昌平':{ '沙河':{ '老男孩':{ '路飞':{ 'Python':{ }} }, '北航':{}, }, '天通苑':{}, '回龙观':{}, }, '朝阳':{}, '东城':{}, }, '上海':{ '闵行':{ "人民广场":{ '炸鸡店':{} } }, '闸北':{ '火车战':{ '携程':{} } }, '浦东':{}, }, '山东':{}, } currert_layer = menu layers = [] #进入下一层的都添加一次进来 while True: for i in currert_layer: print(i) choice = input("进入程序:").strip() if not choice:continue #如果没有选择也继续 if choice in currert_layer: layers.append(currert_layer) #进入下一层之前append上一层进入layers列表 currert_layer = currert_layer[choice] elif choice == 'b' or choice =='B': if len(layers) != 0: currert_layer = layers.pop() #把上一层添加进layers的删除掉 else: print("已经在初始画面!") elif choice == 'q' or choice =='Q': print("程序结束!") exit()
alex 的三级菜单程序堪称经典了
# __*__ coding: utf-8 __*__ __author__ = "david.z" import os def gouwuche(): products = [ ("苹果X", 6888), ("MacPro", 14800), ("小米6", 2499), ("星巴克咖啡", 31), ("Python书籍", 80), ("Nike 鞋子 ", 799), ("儿童车", 1355) ] shopping_list = [] salary = input("请输入您的工资:") while True: if salary.isdigit(): salary = int(salary) while True: for index, item in enumerate(products): print(index, item) # print() user_choice = input("请选择你要购买的商品编号:") if user_choice.isdigit(): user_choice = int(user_choice) if user_choice < len(products) and user_choice >= 0: p_item = products[user_choice] if p_item[1] <= salary: # 买得起 shopping_list.append(p_item) salary -= p_item[1] print("您所购买的商品为 33[32;1m%s 33[0m,您的余额还剩 33[31;1m%s 33[0m" % (p_item, salary)) else: print("