1 #Coding:utf-82 ImportOS3 #declare an empty list store the name of the learner4Member_list = []5 #reads local file raw data, adds local data to member_list, and does not guarantee the second run Member_list6 ifOs.path.exists ('Student.txt'):7File_test = open ('Student.txt','R')8Name_list =File_test.readlines ()9 #The name in the name_list is processed to remove \ n from the nameTen forNameinchname_list: Oneres = Name.strip ('\ n') A #Add the name of the processing complete to member-list - member_list.append (RES) - file_test.close () the Else: - Print 'file does not exist!' - while1: - Print""" + 1. Add student name - 2. Change the student's name + 3. Check the student's name A 4. Delete student names at 0. Exit the program - """ -Select_operation = input ('Please enter the operation number') - #loop to determine if the input number exists - whileSelect_operation<0orSelect_operation>4: -Select_operation = input ('number does not exist, please enter the operation number') in #determine each number and set the appropriate logic - ifSelect_operation = = 1: to #Add Action +Member_name = Raw_input ('Please enter student name:') - #add a name to the list the member_list.append (member_name) * Print '-----added successfully \ n' $ elifSelect_operation = = 2:Panax Notoginseng #Modify Student Name - #first check all the student names, and then set the number of each student, easy to modify the forXinchxrange (0,len (member_list)): + #first remove each value of the list with X as the index, AName=Member_list[x] the PrintX+1,' .', name + #gets the learner number entered because the learner name information is to be modified according to the number. -Select_number = input ('Please enter the learner number to be modified:') $ #loop detection number is correct $ whileSelect_number < 1orSelect_number>Len (member_list): -Select_number = input ('The learner number does not exist, re-enter:') - #modifies the list's data based on the obtained number the #get the new learner name entered by the console -New_name = Raw_input ('Please enter the modified name:')WuyiMEMBER_LIST[SELECT_NUMBER-1] =new_name the Print 'Data modification Successful!n' - elifSelect_operation = = 3: Wu Print '1-Query information based on learner ID' - Print '2-Check all students' AboutSelect_number = input ('Please select a query operation:') $ whileSelect_number! = 1 andSelect_number!=2 : -Select_number = input ('Please re-select the query operation:') - ifSelect_number ==1: -Number = input ('Please enter your enquiry number:') A whileNumber < 1orNumber>Len (member_list): +Number = input ('The learner number does not exist, re-enter:') the PrintMember_list[number-1] - Else: $ forXinchxrange (0,len (member_list)): the #first remove each value of the list with X as the index, theName=Member_list[x] the PrintX+1,' .', name the elifSelect_operation = = 4: - Print '1-Delete by serial number' in Print '2-Delete by name' the Print '3-Delete all learners' theNumber = input ('Select Delete action:') About whileNumber! = 1 andNumber! = 2 andNumber! = 3 : theNumber = input ('Select the correct delete operation:') the ifNumber ==1: thenum = input ('Please enter the student number:') + whileNum<0orNum>Len (member_list): -num = input ('Please enter the correct number of participants:') the member_list.pop (num)Bayi Print 'Delete succeeded \ n' the elifNumber = = 2: theName = Raw_input ('Please enter your name:') - #determines whether the name is in the list, does not exist return true whole is established, if present returns flase condition is false - whileName not inchmember_list: theName = Raw_input ('name does not exist, re-enter:') the member_list.remove (name) the Print 'Delete succeeded \ n' the Else: - whileLen (member_list): the delMember_list[0] the Print 'Delete succeeded \ n' the Else:94 #Exit the Break the #since the Member_list list is updated, the data is kept up to date, and all the data in the list is written directly to the local file. theFile_test = open ('Student.txt','W')98 forXinchxrange (0,len (member_list)): AboutName =Member_list[x] - #Once the name is taken out, each loop is once, and the name taken out is written locally. 101 file_test.write (name)102File_test.write ('\ n')103 #Close File104File_test.close ()
Just learn the python, practice the Code