当前位置:网站首页>Three level menu applet

Three level menu applet

2022-06-26 03:48:00 Just call me ah Jie

Implement a three-level menu , Back off , Quit at any time , You can go back to

menu = {
    ' Beijing ':{
        ' haidian ':{
            ' Wudaokou ':{
                'soho':{},
                ' NetEase ':{},
                'google':{}
            },
            ' Zhongguancun ':{
                ' Iqiyi ':{},
                ' Car home ':{},
                'youku':{},
            },
            ' On the ground ':{
                ' Baidu ':{},
            },
        },
        ' Changping ':{
            ' Shahe ':{
                ' The old boy ':{},
                ' Beihang ':{},
            },
            ' Tiantongyuan ':{},
            ' Huilongguan ':{},
        },
        ' The rising sun ':{},
        ' Dongcheng ':{},
    },
    ' Shanghai ':{
        ' Minhang ':{
            " People's Square ":{
                ' Fried chicken ':{}
            }
        },
        ' Zhabei ':{
            ' Train war ':{
                ' Ctrip ':{}
            }
        },
        ' In the pudong new area ':{},
    },
    ' Shandong ':{},
}

current = menu
gyf=[menu]
while True:
    for i in current.keys():
        print(i)
    a = input('>').strip()
    if a == 'b':
        current=gyf[-1]  # current The last one is to keep the previous menu 
        if len(gyf) > 1: #  Prevent multiple errors when exiting the first level menu 
            gyf.pop()    #  After getting the upper menu, delete the last one , At this point, the last one is the upper level menu 
    elif a in ('q','quit'):
        break
    elif a not in current:
        continue
    else:
        gyf.append(current) # Put the current menu to the last place every time 
        current=current[a]  # Put subordinate menus in current, In this way, the lower level menu will be printed 

原网站

版权声明
本文为[Just call me ah Jie]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202180546015879.html