在字典的三级菜单中添加内容

li = []
go = True
while go:
    for i,v in enumerate(dic,1):
        li.append(v)
        print(i,v)

    u_c = str(input(">>>"))
    if u_c.isdigit():
        u_c = int(u_c)

        li1 = []
        while go:
            for i,v in enumerate(dic[li[u_c-1]],1):
                print(i,v)
                li1.append(v)
            u_c1 = str(input(">>>"))
            if u_c1.isdigit():
                u_c1 = int(u_c1)
            elif u_c1.isalpha():
                u_c1 == u_c1.lower()
                if u_c1 == "b":
                    li1.clear()  # 或者用 del li1[:]
                    break
                elif u_c1 == "q":
                    go = False
                    break
            while go:
                for i in dic[li[u_c-1]][li1[u_c1-1]]:
                    print(i)
                u_c2 = str(input(">>>")) 
                u_c2 = u_c2.lower()
                if u_c2 == "b":
                    li1.clear() #或者用 del li1[:]
                    break
                elif u_c2 == "q":
                    go = False
                    break
    elif u_c.isalpha():
        u_c = u_c.lower()
        if u_c == "i":
            lx = input("类型:")
            if dic.get(lx,1) == 1:
                dic[lx] = {}  #把所输入的类型添加到字典的首层中
            zl = input("种类:")
            if dic[lx].get(zl,1) == 1:
                dic[lx][zl] = []
            while True:
                mc = input("名称:")
                if mc == "q":
                    li.clear()
                    break
                if mc in dic[lx][zl]:
                    print("已经存在!")
                else:
                    dic[lx][zl].append(mc)

 

posted @ 2019-01-08 18:08  成蹊不言  阅读(227)  评论(0编辑  收藏  举报