exit_flag = False # 标志位的作用
menu = {
"JiangSu": {
"NanJing": ["GuLou", "XuanWu"],
"SuZhou": ["XiangCheng", "WuZhong"]
},
"ShangHai": {
"PuDong": ["ZhangJiang", "TangZhen"],
"JingAn": ["ChangPing", "WuNing"]
}
}
while not exit_flag:
for index, key in enumerate(menu.keys()):
print (index, key)
chice_1 = raw_input("Please choose menu to enter:").strip()
if chice_1.isdigit():
chice_1 = int(chice_1)
key_1 = menu.keys()[chice_1]
while not exit_flag:
for index, key in enumerate(menu[key_1]):
print ("-->", index, key)
chice_2 = raw_input("Please choose menu to enter:").strip()
if chice_2.isdigit():
chice_2 = int(chice_2)
key_2 = menu[key_1].keys()[chice_2]
while not exit_flag:
for index, key in enumerate(menu[key_1][key_2]):
print ("-->-->", index, key)
chice_3 = raw_input("Please choose menu to enter:").strip()
if chice_3.isdigit():
print ("This is the last level.....")
elif chice_3 == 'quit':
exit_flag = True
elif chice_3 == 'back':
break
else:
print ('===========Going to Quit=============')
Python:三级菜单
最新推荐文章于 2023-12-05 15:46:52 发布