Day 16 20190131 老男孩python学习第16天 内容整理
作者:互联网
作业讲解视频观看
1. 三级菜单作业重构3个小时
1 menu = { 2 '北京': { 3 '海淀': { 4 '五道口': { 5 'soho': {}, 6 '网易': {}, 7 'google': {} 8 }, 9 '中关村': { 10 '爱奇艺': {}, 11 '汽车之家': {}, 12 'youku': {}, 13 }, 14 '上地': { 15 '百度': {}, 16 }, 17 }, 18 '昌平': { 19 '沙河': { 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 current_layer = menu 46 history = [] 47 while True: 48 for i in current_layer: 49 print(i) 50 choice = input('>:').strip() 51 if not choice: 52 continue 53 if choice == 'q': 54 exit('程序已退出') 55 elif choice in current_layer: 56 if len(current_layer[choice]) > 0: 57 history.append(current_layer) 58 current_layer = current_layer[choice] 59 else: 60 print('当前已是最底层!') 61 elif choice == 'b': 62 if len(history) > 0: 63 current_layer = history[-1] 64 history.pop() 65 else: 66 print('当前已是最顶层!') 67 else: 68 print('输入有误,请重新输入')View Code
2. 上次登录作业讲解 1个小时
文件操作
字典
3. 购物车作业优化 1个小时
加入读取数据文件
优化while
优化if语句
优化exit()
4. 导师考核
标签:layer,16,python,choice,current,print,20190131,else,history 来源: https://www.cnblogs.com/Jack1314/p/10340984.html