1. 程式人生 > >51_work--三級菜單

51_work--三級菜單

please eve long else bre rect rst return not

menu={
    ‘shandong‘:{
        ‘qingdao‘:[‘sifang‘,‘haungdao‘],
        ‘jinan‘:[‘licheng‘,‘zhangqiu‘]
    },
    ‘zhejiang‘:{
        ‘hangzhou‘:[‘xihu‘,‘binjiang‘],
        ‘wnzhou‘:[‘lucheng‘,‘longwan‘]
    },
    ‘guangdong‘:{
        ‘shenzheng‘:[‘futian‘,‘nanshan‘],
        ‘guangzhou‘:[‘zhuhai‘,‘baiyuan‘]
    }
}
flag=True
while flag:
    for i in menu:
        print(i)
    menu1=input(‘Please enter the menu1>>>:‘)
    if menu1 in menu:
        while flag:
            for i1 in menu[menu1]:
                print(i1)
            menu2 = input(‘Please enter the menu2>>>:‘)
            if menu2 in menu[menu1]:
                for i2 in menu[menu1][menu2]:
                    print(i2)
                menu3=input(‘This is the last level menu and press b to return to the previous level >>>:‘)
                if menu3==‘b‘:
                    pass
                elif menu3==‘q‘:
                    flag=False
                else:
                    print(‘The input is incorrect. Please re-enter it‘)
            elif menu2==‘b‘:
                break
            elif menu2==‘q‘:
                flag=False
            else:
                print(‘The input is incorrect. Please re-enter it‘)
    elif menu1 == ‘b‘:
        print(‘The first level menu can not be returned‘)

    elif menu1 == ‘q‘:
        flag = False
    else:
        print(‘The input is incorrect. Please re-enter it‘)

51_work--三級菜單