实现三级菜单功能。
按b返回
按q退出
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Hiuhung Wan
menu = {
"电器": {
"电视": {
"曲面": {},
"超薄": {},
"4k": {},
},
"空调": {
"柜式": {},
"变频": {},
"单冷": {},
},
"冰箱": {
"单门": {},
"双门": {},
"三门": {},
},
},
"手机类": {
"手机": {
"智能手机": {},
"老人手机": {},
"对讲机": {},
},
"配件": {
"壳": {},
"膜": {},
"TF卡": {},
},
"数码": {
"读卡器": {},
"三角架": {},
"手柄": {},
},
},
"电脑": {
"电脑整机": {
"笔记本": {},
"游戏本": {},
"平板": {},
},
"电脑配件": {
"CPU": {},
"SSD": {},
"HDD": {},
},
"外设": {
"键盘": {},
"鼠标": {},
"摄像头": {},
},
},
}
flag = True
while flag:
for i in menu:
print(i)
user_chiose_1 = input("第一层:")
if user_chiose_1 in menu:
while flag:
for x in menu[user_chiose_1]:
print("\t%s" %(x))
user_chiose_2 = input("第二层:")
if user_chiose_2 in menu[user_chiose_1]:
while flag:
for y in menu[user_chiose_1][user_chiose_2]:
print("\t\t%s" % (y))
user_chiose_3 = input("已是第三层了,按b返回或按q退出")
if user_chiose_3 in menu[user_chiose_1][user_chiose_2]:
for z in menu[user_chiose_1][user_chiose_2][user_chiose_3]:
print("\t\t\t%s" % (z))
elif user_chiose_3 == ("q" or "Q"):
flag = False
elif user_chiose_3 == ("b" or "B"):
break
else:
print("输入非法,请检查!")
elif user_chiose_2 == ("q" or "Q"):
flag = False
elif user_chiose_2 == ("b" or "B"):
break
else:
print("输入非法,请检查!")
elif user_chiose_1 == ("q" or "Q"):
flag = False
elif user_chiose_1 == ("b" or "B"):
break
else:
print("输入非法,请检查!")
#!/usr/bin/env pyt