三层菜单1

打印省、市、县三级菜单

可返回上一级

可随时退出程序

menu = {
'北京':{
'海淀':{
'清华':{},
'北大':{}
},
'昌平':{
'沙河':{},
'天通苑':{},
'回龙观':{}
}
},
'上海':{
'闵行':{
'上海发电机厂':{},
'上海汽轮机厂':{},
'上海锅炉厂':{}
},
'松江':{
'东华大学':{
'教学楼':{},
'食堂':{},
'图书馆':{},
'宿舍':{}
},
'上海外国语大学':{},
'华东政法大学':{}
},
'徐汇':{
'百脑汇':{},
'上海交通大学':{},
'铁山家':{}
}
},
'辽宁':{
'沈阳':{
'王寅':{},
'芗芗':{},
'铁西':{}
},
'大连':{
'大连交通大学':{},
'大连医科大学':{}
},
'朝阳':{
'二高':{},
'四中':{},
'板面':{},
'灌汤包':{},
'炖肠':{}
}
}
}

switch = True
while switch:
menu1 = menu

for key in menu1:
    print(key)
print('import back to last step,quit to end or choice to next step:')

choice1 = input('1 step:').strip()

if choice1 == 'back':
    break
if choice1 == 'quit':
    switch = False
    break
if choice1 not in menu1:
    continue

while switch:
    menu2 = menu1[choice1]

    for key in menu2:
        print(key)
    print('import back to last step,quit to end or choice to next step:')

    choice2 = input('2 step:').strip()


    if choice2 == 'back':
        break
    if choice2 == 'quit':
        switch = False
        break
    if choice2 not in menu2:
        continue

    while switch:
        menu3 = menu2[choice2]

        for key in menu3:
            print(key)

        print('import back to last step,quit to end or choice to next step:')

        choice3 = input('2 step:').strip()

        if choice3 == 'back':
            break
        if choice3 == 'quit':
            switch = False
            break
        if choice3 not in menu3:
            continue

猜你喜欢

转载自www.cnblogs.com/agsol/p/11515054.html