User interaction, showing the choice of three-level linkage between provinces and counties
Requirement: User input Hebei, then print the city saved by Hebei, the user input city, then show the county of this city in Hebei province
1DIC = {2 "Hebei": {3 "Shijiazhuang": ["Luquan","Gaocheng","Yuanshi"],4 "Handan": ["Yongnian","She County","ci"],5 },6 "Henan": {7 ...8 },9 "Shanxi": {Ten ... One }, A } - whileTrue: - forIinchDIC: the Print(i) -Shengcheng = input ('Please enter the province [Q exit]:'). Strip () - ifShengcheng = ='Q': - exit () + elifShengchenginchDIC: - whileTrue: + forI2inchDic[shengcheng]: A Print(I2) atShixian = input ('Please enter the city [Q return to the previous layer]:'). Strip () - ifShixianinchDic[shengcheng]: - whileTrue: - fori3inchDic[shengcheng][shixian]: - Print(i3) -FH = input ('That's all, enter Q to return to the previous layer:') in ifFH = ='Q': - Break to Else: + Print('Please re-enter! ') - elifShixian = ='Q': the Break * Else: $ Print('Please re-enter! ')Panax Notoginseng Else: - Print('Please re-enter! ')Level Three menu
Python learning-three-level menu provinces and cities selection