标签:for 其他 span color inpu dict 选择 内容 初识
1 # -*- coding: utf-8 -*- 2 ‘‘‘ 3 Accounting:三级目录,输入目录中选项进入下一级,输入b返回上一级, 4 输入q退出程序,输入其他内容则当前目录继续输入 5 ‘‘‘ 6 dict = { 7 ‘北京‘:{ 8 ‘朝阳‘:{ 9 ‘朝阳群众‘:{ 10 ‘路人甲‘:{}, 11 ‘路人乙‘:{}, 12 ‘路人丙‘:{} 13 }, 14 ‘朝阳群众2‘:{} 15 }, 16 ‘海淀‘:{}, 17 ‘昌平‘:{} 18 }, 19 ‘上海‘:{}, 20 ‘广州‘:{} 21 } 22 exit_flag = False #退出标志位 23 while not exit_flag: 24 for i in dict: 25 print(i) 26 chioce = input(‘选择进入层级1--->>‘) 27 if chioce in dict: 28 while not exit_flag: 29 for i2 in dict[chioce]: 30 print(i2) 31 chioce2 = input(‘选择进入层级2--->>‘) 32 if chioce2 in dict[chioce]: 33 while not exit_flag: 34 for i3 in dict[chioce][chioce2]: 35 print(i3) 36 chioce3 = input(‘选择进入层级3--->>‘) 37 if chioce3 in dict[chioce][chioce2]: 38 while not exit_flag: 39 for i4 in dict[chioce][chioce2][chioce3]: 40 print(i4) 41 chioce4 = input(‘最后层级,输入b返回上一层级--->>‘) 42 if chioce4 == ‘b‘: 43 pass 44 elif chioce4 == ‘q‘: 45 exit_flag = True 46 elif chioce3 == ‘b‘: 47 break 48 elif chioce3 == ‘q‘: 49 exit_flag = True 50 elif chioce2 == ‘b‘: 51 break 52 elif chioce2 == ‘q‘: 53 exit_flag = True 54 elif chioce == ‘q‘: 55 exit_flag = True
在练习时把判断与循环顺序搞错了,头痛了好一阵(if 与 while)
标签:for 其他 span color inpu dict 选择 内容 初识
原文地址:https://www.cnblogs.com/sugar2019/p/10280018.html