04-python3.5-模擬三級選單-省-縣-區域–01

python-python發表於2018-10-23
 1 #!/usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 #Author:XZ
 4 
 5 data = {
 6     `北京`:{
 7         "昌平":{
 8             "沙河":["Oldboy","Test"],
 9             "天通苑":["鏈家地產","我愛我家"],
10             "回龍觀":["北郊農場","天鴻集團"],
11         },
12         "朝陽":{
13             "望京":["賓士","陌陌"],
14             "國貿":["CICC","HP"],
15             "東直門":["Advent","飛信"],
16         },
17         "海淀":{
18             "西三旗":["清景園","清緣裡"],
19             "中關村":["清華大學","北京大學"],
20             "五棵松":["310醫院","名仕醫院"],
21         },
22     },
23     `山東`:{
24         "德州":{},
25         "青島":{},
26         "濟南":{},
27     },
28     `廣東`:{
29         "東莞":{},
30         "常熟":{},
31         "佛山":{},
32     },
33 }
34 exit_flag = False
35 while not exit_flag:
36     for states in data:
37         print(states)
38     user_choice_state = input("請輸入選擇的省份:>>>")
39     if user_choice_state in data:
40         while not exit_flag:
41             for districts in data[user_choice_state]:
42                 print("	",districts)
43             user_choice_district = input("請輸入選擇的區/縣:>>>")
44             if user_choice_district in data[user_choice_state]:
45                 while not exit_flag:
46                     for areas in data[user_choice_state][user_choice_district]:
47                         print("		",areas)
48                     user_choice_area = input("請輸入選擇的地段:>>>")
49                     if user_choice_area in data[user_choice_state][user_choice_district]:
50                         for units_list in data[user_choice_state][user_choice_district][user_choice_area]:
51                             print("			", units_list)
52                         user_choice_return = input("當前已是末端,如需返回請輸入b:>>>")
53                         if user_choice_return == `b`:
54                             pass
55                         elif user_choice_return == `q`:
56                             exit_flag = True
57                     if user_choice_area == `b`:
58                         break
59                     elif user_choice_area == `q`:
60                         exit_flag = True
61             if user_choice_district == `b`:
62                 break
63             elif user_choice_district == `q`:
64                 exit_flag = True

 

相關文章