Python Practice _module01-1-3-level menu _2

Source: Internet
Author: User
Tags rar

Another way to implement level 3 menus: looping

The way of the function: http://www.cnblogs.com/jailly/p/6709573.html

1. First create a dictionary that indicates the mapping relationship between the level 3 directory structure, and then save it to a pickle file to invoke

1 ImportPickle2 3Dir_windows = ['Explorer.exe']4Part_c = {'Windows': Dir_windows}5 6Dir_setup = ['Rhel-7.3.iso','Securecrt6.rar']7Dir_program = ['Putty.exe','PhotoshopCC2016.exe']8Part_d = {'Setup': Dir_setup,' Program': Dir_program}9 TenDir_video = ['June's name は.mp4'] OneDir_game = ['Nier:automata','Sid meier\ ' s civilization VI'] APart_e = {'Video': Dir_video,'Game': Dir_game} -  -Root = {'C': Part_c,'D': Part_d,'E': Part_e} the  -With open ('DIR.PKL','WB') as F: -Pickle.dump (ROOT,F)

2. Main program

1 #!/usr/bin/env Python32 #-*-coding:utf-8-*-3 #author:jailly4 5 " "6 The directory structure of level 3 to simulate the level three menu, the directory structure is as follows:7 C8 Windows9 Explorer.exeTen D One Setup A Rhel-7.3.iso - Securecrt6.rar -  Program the Putty.exe - PhotoshopCC2016.exe - E - Video + June's name は.mp4 - Game + Nier:automata A Sid Meier ' s civilization VI at " " -  - ImportPickle -  - defMain (Root): -n = 1 inSelect1 =None -Select2 =None toSELECT3 =None +  -      whileN: the         ifn = = 1: *             if  notSelect1: $                 Print('Welcome to the level%d directory, which has the following directory/file:%s'% (n,','. Join (Sorted (Root.keys () )))Panax NotoginsengSelect1 = input ('Please select the action you want to perform: ("[Directory Name]": Enter directory; "q": Exit):') -  the             ifSelect1inchRoot: +n = 2 A                 Continue the             elifSelect1 = ='Q': +                  Break -             Else: $Select1 = input ('command input error, please re-enter:') $                 Continue -  -         elifn = = 2: the             if  notSelect2: -                 Print('Welcome to the level%d directory, which has the following directory/file:%s'% (n,','. Join (Sorted (Root[select1].keys () )))WuyiSelect2 = input ('Please select the action you want to perform: ("[Directory Name]": Enter directory; "B", return to the previous level; "Q": Exit):') the  -             ifSelect2inchRoot[select1]: Wun = 3 -                 Continue About             elifSelect2 = ='b': $n = 1 -                 Continue -             elifSelect2 = ='Q': -                  Break A             Else: +Select2 = input ('command input error, please re-enter:') the                 Continue -  $         elifn = = 3: the             if  notselect3: the                 Print('Welcome to the level%d directory, which has the following directory/file:%s'% (n,','. Join (Sorted (ROOT[SELECT1][SELECT2) ))) theSELECT3 = input ('Please select the action you want to perform: ("B", return to the previous level; "Q": Exit):') the  -             ifSelect3 = ='b': inn = 2 the                 Continue the             elifSelect3 = ='Q': About                  Break the             Else: theSELECT3 = input ('command input error, please re-enter:') the                 Continue +  - if __name__=='__main__': the BayiWith open ('DIR.PKL','BR') as F: theRoot =pickle.load (f) the  -Main (Root)

Python Practice _module01-1-3-level menu _2

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.