標籤:ati roo author 映射 程式 auto ted exp target
3級菜單的另一種實現方式:迴圈
函數的方式:http://www.cnblogs.com/jailly/p/6709573.html
1.先建立一個能夠表明3級目錄結構之間映射關係的字典,然後將其存入一個pickle檔案以便調用
1 import pickle 2 3 dir_windows = [‘explorer.exe‘] 4 part_C = {‘windows‘: dir_windows} 5 6 dir_setup = [‘rhel-7.3.iso‘, ‘SecureCRT6.rar‘] 7 dir_program = [‘putty.exe‘, ‘PhotoshopCC2016.exe‘] 8 part_D = {‘setup‘: dir_setup, ‘program‘: dir_program} 9 10 dir_video = [‘君の名は.mp4‘]11 dir_game = [‘NieR: Automata‘, ‘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.主程式
1 #! /usr/bin/env python3 2 # -*- coding:utf-8 -*- 3 # Author:Jailly 4 5 ‘‘‘ 6 以3級的目錄結構類比三級菜單,目錄結構如下:: 7 C 8 windows 9 explorer.exe10 D11 setup12 rhel-7.3.iso13 SecureCRT6.rar14 program15 putty.exe16 PhotoshopCC2016.exe17 E18 video19 君の名は.mp420 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 == 1:35 if not select1:36 print(‘歡迎進入%d級目錄,該目錄下有如下目錄/檔案:%s‘% (n,‘、‘.join(sorted(root.keys()))))37 select1 = input(‘請選擇您想要執行的操作:(“[目錄名]”:進入目錄;“q”:退出):‘)38 39 if select1 in root:40 n = 241 continue42 elif select1 == ‘q‘:43 break44 else:45 select1 = input(‘指令輸入錯誤,請重新輸入:‘)46 continue47 48 elif n == 2:49 if not select2:50 print(‘歡迎進入%d級目錄,該目錄下有如下目錄/檔案:%s‘%(n,‘、‘.join(sorted(root[select1].keys()))))51 select2 = input(‘請選擇您想要執行的操作:(“[目錄名]”:進入目錄;“b”,返回上一級;“q”:退出):‘)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(‘指令輸入錯誤,請重新輸入:‘)63 continue64 65 elif n == 3:66 if not select3:67 print(‘歡迎進入%d級目錄,該目錄下有如下目錄/檔案:%s‘ % (n, ‘、‘.join(sorted(root[select1][select2]))))68 select3 = input(‘請選擇您想要執行的操作:(“b”,返回上一級;“q”:退出):‘)69 70 if select3 == ‘b‘:71 n = 272 continue73 elif select3 == ‘q‘:74 break75 else:76 select3 = input(‘指令輸入錯誤,請重新輸入:‘)77 continue78 79 if __name__ == ‘__main__‘:80 81 with open(‘dir.pkl‘, ‘br‘) as f:82 root = pickle.load(f)83 84 main(root)
python練習_module01-1-3級菜單_2