Files: Practise2.tar
Exercise: Multilevel Menus
- Level three Menu
- Select Menu
- Lists and data dictionaries
#!/usr/bin/env python#Author:austindefmatch_name (level): _file= Open ("Dictionary.txt","R") line=_file.readline () whileline : _level= Line.split (":") [0] _name= Line.split (":") [1][:-1] if_level = =Level:name=_name break line=_file.readline () _file.close ( )returnnamedefLevel1_print ():Print("------List------") _file= Open ("List.txt","R") line=_file.readline () _tmp_level="" whileLine:level1= Line.split (":") [0]iflevel1! =_tmp_level:name=match_name (level1)Print(level1,name) _tmp_level=Level1 line=_file.readline ()Print("----------------") chose= Input ("Plese chose One: (1/2/3)") _file.close ()returnchosedefLevel2_print (level):Print("-----{level}-----". Format (level=level )) _file= Open ("List.txt","R") line=_file.readline () _tmp_level="" whileLine:level1= Line.split (":") [0] Level2= Line.split (":") [1] ifLevel1 = = Level andlevel2! =_tmp_level:name=match_name (level2)Print(level2,name) _tmp_level=Level2 line=_file.readline () _file.close ( )Print("----------") chose= Input ("back or chose One:") returnchosedefLevel3_print (level):Print("-----{level}-----". Format (level=level )) _file= Open ("List.txt","R") line=_file.readline () _tmp_level="" whileLine:level2= Line.split (":") [1] Level3= Line.split (":") [2][:-1] ifLevel2 = = Level andlevel3! =_tmp_level:name=match_name (level3)Print(name) _tmp_level=Level3 line=_file.readline () _file.close ( )Print("----------") chose= Input ("back or chose One:") returnChosecurrent_level= 1Last_chose=""Current_chose=""chose="" whileTrue:ifCurrent_level = = 1: Chose=level1_print () current_level= 2elifCurrent_level = = 2 andchose! ="b": Last_chose=chose chose=level2_print (chose) current_level= 3elifCurrent_level = = 3 andchose! ="b": Chose=Level3_print (chose)elifCurrent_level = = 3 andchose = ="b": Chose=level2_print (last_chose) current_level= 2elifCurrent_level = = 2 andchose = ="b": Chose= Level1_print ()
Postscript:
1. Shanbao programmer did not write comments
2. There is a bug, it is hard to write tired to Change. Some places feel bad about Themselves.
3. Wait until you see how Alex wrote it, update it.
Python week1-exercise Level 23 Directory