Python exercise _ module01-1-3 menu _ 2, _ module01-1-3_2

Source: Internet
Author: User

Python exercise _ module01-1-3 menu _ 2, _ module01-1-3_2

Another Implementation Method of Level 3 menus: loop

Function Method: http://www.cnblogs.com/jailly/p/6709573.html

 

1. Create a dictionary that indicates the ing between three levels of directory structures, and store it in a pickle file for calling

1 import pickle 2 3 dir_windows = require 'cmder.exe '] 4 part_C = {'windows': dir_windows} 5 6 dir_setup = ['rhel-7.3.iso', 'SecureCRT6.rar '] 7 dir_program = require 'putty.exe ', 'PhotoshopCC2016.exe '] 8 part_D = {'setup': dir_setup, 'program': dir_program} 9 10 dir_video = 'jun Jun Ming .mp4 '] 11 dir_game = ['nier: A ', 'sid Meier \'s Civilization VI '] 12 part_E = {'video': dir_video, 'game': dir_game} 13 14 root = {'C': part_C, 'D': part_D, 'E': part_E} 15 16 with open ('dir. pkl ', 'wb') as f: 17 pickle. dump (root, f)

 

2. Main Program

1 #! /Usr/bin/env python3 2 #-*-coding: UTF-8-*-3 # Author: Jailly 4 5 ''' 6 simulate Level 3 menus with a level 3 directory structure, the directory structure is as follows: 7 C 8 windows 9 explorer.exe 10 D11 setup12 rhel-7.3.iso13 SecureCRT6.rar14 program15 putty.exe 16 PhotoshopCC2016.exe17 E18 video19 は.mp4 20 game21 NieR: automata22 Sid Meier's Civilization VI 23 ''' 24 25 import pickle26 27 def main (root): 28 n = 129 select1 = None30 select2 = None31 select3 = None32 33 while n: 34 if n = if not select1: 36 print ('Welcome to the % d directory, which contains the following directory/file: % s' % (n, ','. join (sorted (root. keys () 37 select1 = input ('select the operation you want to perform: ("[directory name]": Enter the Directory; "q": Exit ):') 38 39 if select1 in root: 40 n = 241 continue42 elif select1 = 'q': 43 break44 else: 45 select1 = input ('COMMAND input error, please enter again :') 46 continue47 48 elif n = if not select2: 50 print ('Welcome to the % d directory, which contains the following directory/file: % s' % (n, ','. join (sorted (root [select1]. keys () 51 select2 = input ('select the operation you want to perform: ("[directory name]": Enter the Directory; "B", return to the upper level; "q": Exit): ') 52 53 if select2 in root [select1]: 54 n = 355 continue56 elif select2 =' B ': 57 n = 158 continue59 elif select2 = 'q': 60 break61 else: 62 select2 = input ('COMMAND input error, please enter again :') 63 continue64 65 elif n = 3: 66 if not select3: 67 print ('Welcome To The % d directory, which contains the following directories/files: % s' % (n ,','. join (sorted (root [select1] [select2]) 68 select3 = input ('select the operation you want to perform: ("B", return to the upper level; "q ": exit): ') 69 70 if select3 =' B ': 71 n = 272 continue73 elif select3 = 'q': 74 break75 else: 76 select3 = input ('COMMAND input error, please enter again: ') 77 continue78 79 if _ name _ =' _ main __': 80 81 with open ('dir. pkl ', 'br') as f: 82 root = pickle. load (f) 83 84 main (root)

 

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.