Looping through lists (for loops) list common operations ("add", "delete", "" Change "," Check "(append) to delete (" Pop "," del "," Remove ") to change (" first find the user subscript, in the modified, as the list elements assigned to the same ") check (in, don't in)
#coding =utf-8 name=["Zhangsan", "Wangwu", "Test" print ("*" *40) print ("Welcome to Business Card management system") print ("Please follow the prompts.")
") Print (" * "*40) #打印列表 def ceshi (): Print (" Content in current business card system ") I=0 for J-in Name:print (" name[%d]=%s "% (i,j)) I+=1 while True: #打印用户提示 print (select the corresponding feature) print (Find user select: 1) Print (Modify User: 2 ") Print (" Delete User select: 3 "Print (Add user select: 4") Print ("Exit application Please choose: 5") a=input ("Please enter your choice:") if A==1:findname=raw_input (
"Please enter name for query") if FindName in Name:print ("found") else:print ("Not Found") Elif a==2:
Ceshi () i=input ("Please enter the user number to modify") Temp=raw_input ("Please enter the modified username") if I<len (name): Old=name[i] name[i]= (temp) print (user name%s has been modified to%s% (old,temp)) else:print (' User serial number does not exist
In ') elif A==3:ceshi () d=input ("Please select Delete action to make") print (delete by subscript: 1) print ("Delete last element: 2") Print (delete according to the value of element: 3) If d==1:
H=input (' Enter the serial number of the user to be deleted ') del name[h] if H<len (name): print ("delete succeeded")
Else:print ("This user number does not exist") elif D==2:name.pop () print ("Delete succeeded") Elif d==3:val=input ("Please enter the username to be removed") name.remove ('%s '%val) print ("Delete succeeded") elif A==4:print ("******** before adding user Data ********") Ceshi () temp=raw_input ("Enter the name of the user to add") name.append (t EMP) Print ("******** User Data ********") Ceshi () elif a==5:break else:p Rint ("Input error, please re-enter.") ")