1. 程式人生 > >python學習-三級菜單省市選擇

python學習-三級菜單省市選擇

河北省 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 in
dic[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學習-三級菜單省市選擇