Because is the beginner, the code if has insufficient, welcome to point out!
This blog record my way of programming, record the knowledge learned, share the learning experience!
This is one of my homework.
The first analysis requires:
- Create a TXT file to store your account number and password
- Implement the ability to add, delete, modify, and view files.
Analysis Ideas:
- Write a menu of choices first
- List the custom functions we want to write
- The main way to implement add, delete, modify, and view functions is to read the file to return a list and then add, delete, modify, and view the list and then write the list to the file.
1 defJia (LIST):#1 Adding functions2 Print('blank plus enter to exit! ')3 whileTrue:4S = input ('Enter your account:')5 if(s==' '):6 Break7S2=input ('Enter Password:')8List.append (s+' '+s2+'\ n')9With open ('Wj-4.txt','W') as F:Ten f.writelines (LIST) One A defCha (LIST):#2 Viewing Functions - Print('the contents of the file are as follows:') - forIinchLIST: the Print(I.strip ('\ n')) -Input"Press any key to return to the menu! ") - Cai (LIST) - + defShan (LIST):#3 Deleting a function - Print('input-1 exit!') + whileTrue: AR = Int (input ('Please enter to delete the first few:')) at if(R==-1): - Break - delList[r-1] -With open ('Wj-4.txt','W') as F: - f.writelines (LIST) - in defGai (LIST):#5 Modifying functions - Print('input-1 exit! ') to whileTrue: +R = Int (input ('Please enter the modification of the first few:')) - if(R==-1): the Break *R2 = input ('Enter the modified character:') $ delList[r-1]Panax NotoginsengList.insert (R-1, R2) - Print(LIST) the + defDu ():#Read file Functions AWith open ('Wj-4.txt','R') as F: theLIST =F.readlines () + returnLIST - $ defCai (LIST):#Menu Functions $ whileTrue: - Print('menu selection: \ n (1) Add function \ n (2) view function \ n (3) Delete function \ n (4) modify function \ n (5) Exit') -A=int (Input ('Please enter:')) the if(a==1): - Jia (LIST)Wuyi elif(a==2): the cha (LIST) - elif(a==3): Wu Shan (LIST) - elif(a==4): About gai (LIST) $ elif(a==5): - Print('Exit Success! \ n Welcome to use next time! ') - Break - Else:Print('Please enter your selection correctly!') A + if __name__=='__main__': the Try: -LIST = Du ()#Return to list $Cai (LIST)#Menu the except:Print('An unknown error has occurred! ')
Test diagram:
This content mainly examines the familiar with the list and the file.
Python3 to the local TXT file to add, delete, modify, view function.