Python week1-exercise Level 23 Directory

Source: Internet
Author: User
Tags readline

Files: Practise2.tar

Exercise: Multilevel Menus

    1. Level three Menu
    2. Select Menu
    3. 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 ()


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

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: 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.