python學習-三級菜單省市選擇
阿新 • • 發佈:2017-07-12
河北省 lap strip() pre color splay 重新 輸入 elif
用戶交互,顯示省市縣三級聯動的選擇
要求:用戶輸入河北,則打印河北省下的市,用戶輸入市,則顯示該河北省的這個市下的縣
1 dic = { 2 "河北": { 3 "石家莊": ["鹿泉", "槁城", "元氏"], 4 "邯鄲": ["永年", "涉縣", "磁縣"], 5 }, 6 "河南": { 7 ... 8 }, 9 "山西": { 10 ... 11 }, 12 } 13 while True: 14 for i in dic: 15 print三級菜單(i) 16 shengcheng = input(‘請輸入省[q退出]: ‘).strip() 17 if shengcheng == ‘q‘: 18 exit() 19 elif shengcheng in dic: 20 while True: 21 for i2 in dic[shengcheng]: 22 print(i2) 23 shixian = input(‘請輸入市[q返回上一層] : ‘).strip() 24 if shixian indic[shengcheng]: 25 while True: 26 for i3 in dic[shengcheng][shixian]: 27 print(i3) 28 fh = input(‘只有這些了,輸入q返回上一層: ‘) 29 if fh == ‘q‘: 30 break 31 else: 32 print(‘請重新輸入!‘) 33 elif shixian == ‘q‘: 34 break 35 else: 36 print(‘請重新輸入!‘) 37 else: 38 print(‘請重新輸入!‘)
python學習-三級菜單省市選擇