Python之三层菜单

时间:2023-03-09 16:32:25
Python之三层菜单
三层菜单,根据用户所选数字,进入子菜单。一级一级呈现。
 menu = {
'Beijing': {
"ChaoYang": {
"CBD": ['CICC', 'CCTV'],
"JinRongJie": ["CT"],
"Wangjing": ["Momo", "ChuiZI"]
},
"HaiDian": ['Baidu', 'Youku']
},
'Shanghai': {
"PuDong": ["Ctrip", "One Shop"],
"PuXi": ["China Bank", "America Bank"]
}
}
exit_flag = False
while not exit_flag:
for index, key in enumerate(menu.keys()):
print(index, key)
choice_1 = input("Please choose menu to enter:").strip()
if choice_1.isdigit():
choice_1 = int(choice_1) key_1 = list(menu.keys())[choice_1]
while not exit_flag:
for index, key in enumerate(menu[key_1]):
print('-->', index, key)
choice_2 = input("Please choose menu to enter:").strip()
if choice_2.isdigit():
choice_2 = int(choice_2) key_2 = list(menu[key_1].keys())[choice_2]
while not exit_flag:
for index, key in enumerate(menu[key_1][key_2]):
print('-->-->', index, key)
choice_3 = input("Please choose menu to enter:").strip()
if choice_3.isdigit():
print("This is the last level...")
elif choice_3 == 'quit':
exit_flag = True
elif choice_3 == 'back':
break
else:
print("====Going to quit==== ")

注:此版本为Python3.0版本