The main practice of nesting loops and flags is how to use them:
#!/usr/local/python/bin/python3.6
#-*-coding:utf-8-*-
data = {
"China": {"Hebei": ["Shijiazhuang", "Langfang", "Baoding"], "Sichuan": ["Chengdu", "Chongqing", "Nanchong"], "Hubei": ["Wuhan", "Huangshi", "Xiangyang"]},
"USA": {"Washington": ["Chicago", "San Francisco", "Atlanta"], "New York": ["Bronx", "King", "Manhattan"], "Texas": ["Houston", "Dallas", "San Antonio"]}
}
Flag = False
While not flag:
For I in data:
Print (i)
Choice = input ("Please select:")
If choice in data:
While not flag:
For j in Data[choice]:
Print (j)
Choice2 = input ("Please select:")
If Choice2 in Data[choice]:
While not flag:
For K in Data[choice][choice2]:
Print (k)
Choice3 = input ("Last layer," E "returns to the previous level," Q "Exits:")
if Choice3 = = "E":
Break
elif Choice3 = = "Q":
Flag = True
if Choice2 = = "E":
Break
elif Choice2 = = "Q":
Flag = True
if choice = = "Q":
Flag = True
Python Level three Menu