3級菜單實現---low版

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:xyzhang

import json

def menu():
    file=open("menu",'r',encoding='utf-8')
    str=""
    for f in  range(51):
       str=str+file.readline()
    dic=json.loads(str)
    file.close()
    return dic
dict=menu()

def wl(dc):
    while True:
        for m in  dc:
            print(m,type(m))
        butter=input("\t----->請輸入顯示的內容/q退出/b返回:")
        if butter in dc:
            wl(dc[butter])
        elif butter == "q":
            return exit()
        elif butter == "b":
            for k1 in  dict.keys():
                if m in dict.keys() or m in dict[k1].keys():
                    olddc=dict
                    wl(olddc)
                for k2 in dict[k1].keys():
                    if m in dict[k1][k2]:
                        olddc=dict[k1]
                        wl(olddc)
                    for k3 in  dict[k1][k2].keys():
                        if m in dict[k1][k2][k3]:
                            olddc=dict[k1][k2]
                            wl(olddc)

        else:
            print("沒有對應的內容請重輸入!!!")

wl(dict)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章