Python Job 5: Multilevel Menu

Source: Internet
Author: User

# Job 5: Multilevel Menu
# level Three menu, province, city, county, company, ask the program to start, allow the user to choose to go to each sub-menu
# You can return to the parent menu at any level menu, or you can exit the program
# new Knowledge points required: list, dictionary
#
Ideas
# Create a dictionary, three-layer nested dictionary
#逐层提取key字段,
#先不管各种可能, to write the main program, that is, a variety of choices are good conditions can be realized, and then add a variety of possible
#这个地方其实是重点考察while循环里面的continue和break
#出于程序简化, does not consider the input of the digital range, input is not a number, q, B, the case of three
Dict1={        "Save 1":{            "City One":{                "County 111":{                    "Company 1111:{}",                    "Company 1112:{}"                },                "County":{                    "Company 1121:{}",                    "Company 1122:{}"                }            },            "City":{                "County 121":{                    "Company 1211:{}",                    "Company 1212:{}"                },                "County 122":{                    "Company 1221:{}",                    "Company 1222:{}"                }            },            "City":{                "County 131":{},"County":{}            }        },        "Save 2":{            "City":{                "County 211":{},"County 212":{}            },            "City":{                "County 221":{},"County 222":{}            },            "City":{                "County 231":{},"County 232":{}            }        },        "Save 3":{            "City":{                "County 311":{},"County 312":{}            },            "City":{                "County 321":{},"County 222":{}            },            "City":{                "County 331":{},"County 332": {}}}}judge=True whileJudge:list1=list (Dict1.keys ()) List1.sort ()Print("The level_1 menu:")     forIndex,iteminchEnumerate (list1):Print(index,item) Choice1= Input ("Please choose Level_1:")    ifchoice1.isdigit (): Choice1=Int (choice1) choice_key1=List1[choice1] List2=list (Dict1.get (choice_key1)) List2.sort () whileJudge:Print("The level_2 menu:")             forIndex, iteminchEnumerate (list2):Print(Index, item) CHOICE2= Input ("Please choose level_2:")            ifchoice2.isdigit (): Choice2=Int (choice2) Choice_key2=List2[choice2] List3=list (Dict1.get (choice_key1). Get (Choice_key2)) List3.sort () whileJudge:Print("The level_3 menu:")                     forIndex, iteminchEnumerate (LIST3):Print(Index, item) Choice3= Input ("Please choose Level_3:")                    ifchoice3.isdigit (): Choice3=Int (choice3) Choice_key3=List3[choice3] List4=list (Dict1.get (choice_key1). Get (Choice_key2). Get (Choice_key3)) List4.sort () Print("The level_4 menu:")                         forIndex, iteminchEnumerate (LIST4):Print(Index, item) Choice4= Input ("It ' s The last level,please come back:")                        ifChoice4 = ="Q":                            #when the position is empty, you can jump out of multiple loops continuouslyJudge =False#here is all the loops that jump out of this while loop                             Break                        elifChoice4 = ="b":                            #This just jumps out of a loop in this while loop .                            Continue                    elifChoice3 = ="Q": Judge=False Break                    elifChoice3 = ="b":                         Break            elifChoice2 = ="Q": Judge=False Break            elifChoice2 = ="b":                 Break    elifChoice1 = ="Q":#is the Q exitJudge =FalseElse:#not Q nor number, re-elect        Print("Please choose the number .")

Python Job 5: Multilevel Menu

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.