#!/usr/bin/env python
#-*-Coding:utf-8-*-
Provice = {
"Jiangsu Province": {"Suzhou": {' Industrial park ', ' gu Soviet area ', ' Wuzhong District '}, ' Wuxi ': {' Xishan District ', ' New district ', ' South Pool '},
"Hubei Province": {"Wuhan": {' Jianghan District ', ' Jiang ' an ', ' Hongshan District '}, "Yichang": {' Yiling District ', ' Zhijiang ', ' Xiling District '}},
"Zhejiang Province": {"Hangzhou": {' upper Town ', ' Lower Town ', ' Gongshu District '}, ' Huzhou ': {' Nanxun ', ' wuxing ', ' Anji County '}},
"Anhui Province": {"Hefei": {' Luyang District ', ' Shushan District ', ' Qionghai area '}, ' Wuhu ': {' Jiujiang District ', ' Xinwu District ', ' Fanchang area '}}
}
For I in range (3): # Loops 3 times prevents unlimited calls
Print "\033[31;1m----------administrative map---------------\033[0m"
For Pro in Provice.keys ():#获取省信息列表, here you can assign Provice.keys () to a variable, such as Sheng_name_list = Provice.keys (), and then sheng# _ Name_list to traverse
Print "\033[29;1m ============%s=============\033[0m"% pro# Printing province name
Print "\033[34;1m----------------------------------------------------\033[0m"
Proname = raw_input ("Please enter the name of the province you want to see:")
Jump_up_flag = False #定义标志位用来跳出整个循环
If Proname not in Provice.keys ():#判断输入省份名字如果不在地图中
continue# jump out of this loop, back to the beginning of the loop
else:#如果在地图列表中则进行如下遍历操作
Print "\033[33;1m%s contains the following cities: \033[0m"% (proname)
For S_name in Provice[proname].keys ():#遍历省份列表然后打印输出
Print "\033[32;1m%s \033[0m"% (s_name)#输出省份名字列表
While True:
Cs_name = Raw_input ("Enter the city name to view:")
Chengshi_list = Provice[proname].keys ()
If Cs_name in Chengshi_list:
For area in Provice[proname][cs_name]:
Print "\033[32;1m%s \033[0m"% (area)
Print "\033[31;1m-----------------------------\033[0m"
Else
Print "\033[31;1m The city name you entered \033[34;1m%s \033[0m\033[31;1m does not exist please re-enter! \033[0m "% (cs_name)
Continue
Jump_tag = raw_input ("\033[32;1m Please exit: 1 exit, 2 return to the top, any input return to the previous layer: \033[0m")
"""
Determine the user's input: If you enter 1, set Jump_up_flag to True and then jump out of the while loop, return to the parent directory, and judge the code for the flag bit in the previous layer of code
If the flag bit is true execution break will jump out of the entire loop
If you enter 2. The direct break jumps out while loops to the parent directory!
"""
if Jump_tag = = "1":
Jump_up_flag = True
Break
if Jump_tag = = "2":
Break#如果jump_tag赋值为2, jump out of the while loop to the upper for loop
If Jump_up_flag:#判断如果标志位为True, the following break code will be executed to jump out of the entire loop.
Break
else:#如果标志位 (that is, Jump_up_flag) is false, the direct execution continue terminates the for loop into the next for loop
Continue
else:#如果超出三次输入, jump out of the entire for loop
Print "\033[31;1m Information Invalid please re-enter! 3 errors after the program will exit! \033[0m "
Summary: The focus of this case is the identification bit, using the assignment of the identity bit to judge the loop:
Like what:
if Jump_tag = = "1":
Jump_up_flag = True
Break
if Jump_tag = = "2":
break# if the Jump_tag is assigned a value of 2, jump out of the while loop to the upper for loop
If Jump_up_flag: #判断如果标志位为True, the following break code will be executed to jump out of the entire loop.
Break
in Jump_tag = = "1" re-modify Jump_up_flag = True, affect the next time whether to jump out of the entire cycle of thought, this is the finishing touch of the case of the pen
The other is:
For I in range (3):
--------------
--------------
Else
Use with more than three times to exit the For loop directly
This article from "Flat Light is true" blog, please be sure to keep this source http://cryan.blog.51cto.com/10837891/1722873
Write level three menu----map