#author:zhouyuarea = { ' Guangdong ':{ ' Jieyang ':{ ' puning ':{ ' Lake ', ' Plum Pond ', ' Quicksand ' }, ' Hongyang ': {' 1 ', ' 2 '}, ' Jiexi ': {' 1 ', ' 2 '}}, ' Shenzhen ': {' 1 ', ' 2 '}, ' Guangzhou ': {' 1 ', ' 2 '} }, ' Beijing ': {' 1 ', ' 2 '}, ' Sichuan ': {' 1 ', ' 2 '}} #先进入循环while true: #打印出省份 for i in area: print (i) #让用户选择省份 choose = input ("Please select Province:") #判断用户输入的省份在字典里面存在与否. The presence is down execute not return # here to note, Choose in area means that the user input of the area is not present in the #area dictionary, if not exist to see if the user input is q, if the Q is to exit if choose in area: #如果If判断是True的话, that should go into a cycle, but also constantly choose the city, #所以下面一定要是一个循环 while true: #打印出城市 for i2 in area[choose]: print (i2) #让用户输入城市 choose1 = input ("Please select City:") #判断用户输入的城市存不存在我们的列表中, if present, enter a loop , #如果不存在就看看用户输入的是否为q, if Q is the exit, if B is the return # The following explanation is the same don't say it allSolution, if there is no understanding can add me:1090139534 if choose1 in area[choose]: while True: for i3 in area[choose][choose1]: print (i3) choose2 = input ("Please select County:") if choose2 in area[choose][choose1]: for i4 in area[choose][choose1][choose2]: print (I4) while true: choose3 = input ("input ' B ' can return: ") if choose3 == ' B ': break elif choose2 == ' Q ': exit ("Thankyou for use") elif choose2 == ' B ': break elif choose1 == ' Q ': exit ("Thankyou for use") elif choose1 == ' B ': break elif choose == ' Q ': exit ("Thank you foruse")
This article is from "Love Zhou Yu" blog, please be sure to keep this source http://izhouyu.blog.51cto.com/10318932/1964447
Python's third-level menu