标签:tin 返回 笔记 env 百度 三级菜单 bsp 汽车 http
需求:
1 #!/usr/bin/env python3 2 #-*- coding:utf-8 -*- 3 ‘‘‘ 4 Time:2018/5/3 16:23 5 File:三层菜单 6 Author:ly 7 ‘‘‘ 8 menu = { 9 ‘北京‘:{ 10 ‘海淀‘:{ 11 ‘五道口‘:{ 12 ‘soho‘:{}, 13 ‘网易‘:{}, 14 ‘google‘:{} 15 }, 16 ‘中关村‘:{ 17 ‘爱奇艺‘:{}, 18 ‘汽车之家‘:{}, 19 ‘youku‘:{}, 20 }, 21 ‘上地‘:{ 22 ‘百度‘:{}, 23 }, 24 }, 25 ‘昌平‘:{ 26 ‘沙河‘:{ 27 ‘老男孩‘:{}, 28 ‘北航‘:{}, 29 }, 30 ‘天通苑‘:{}, 31 ‘回龙观‘:{}, 32 }, 33 ‘朝阳‘:{}, 34 ‘东城‘:{}, 35 }, 36 ‘上海‘:{ 37 ‘闵行‘:{ 38 "人民广场":{ 39 ‘炸鸡店‘:{} 40 } 41 }, 42 ‘闸北‘:{ 43 ‘火车站‘:{ 44 ‘携程‘:{} 45 } 46 }, 47 ‘浦东‘:{}, 48 }, 49 ‘山东‘:{}, 50 } 51 Current_layer = menu # 当前层 52 53 Next_layer = [ menu ] # 下一层 54 55 exit_flag = False 56 57 while not exit_flag: 58 for i in Current_layer:59 print(i) 60 choice = input("请输入你的选择|B返回|Q退出:").strip() 61 62 if choice in Current_layer: # 如果在当前层里 63 Next_layer.append(Current_layer) # 则将当前层添加到下一层 64 Current_layer = Current_layer[choice] 65 66 if choice == ‘b‘.casefold(): 67 if len(Next_layer) == 0: 68 continue 69 Current_layer = Next_layer[-1] # 取到上一层赋值给当前层 70 Next_layer.pop() 71 # print(Next_layer) 72 73 if choice== ‘q‘.casefold(): 74 exit_flag = True
标签:tin 返回 笔记 env 百度 三级菜单 bsp 汽车 http
原文地址:https://www.cnblogs.com/yjiu1990/p/9012714.html