One of the areas to be aware of is that if you are using a version of 3.6, then all of the input () used to receive the information from the outside world is input (), and if it is version 2.7, then the string to be received is raw_input () ( Automatically converts the received information into a string, even if you enter 12345 that is also the string 12345)
#-*-coding:utf-8-*-Print("********** Welcome to the new business card management system **********") Card_infors= []#used to store business cardsdefPrint_menu ():"""Finish the Print function menu""" Print("="*42) Print("Business Card management system V0.01") Print("1. Add a new business card") Print("2. Delete a business card") Print("3. Modify a business card") Print("4. Query a business card") Print("5. Show All business cards") Print("6. Exit the system") Print("="*42)defadd_new_card_infor ():"""complete the Add a new business card"""new_name= Input ("Please enter a new name:")#Entry of InformationNEW_QQ = Int (input ("Please enter the new QQ:")) New_weixin= Int (Input ("Please enter a NEW:")) New_addr= Input ("Please enter a new address:") New_infor= {}#define a new dictionary to store a new business cardnew_infor['name'] = New_name#Entry of Informationnew_infor['QQ'] =new_qq new_infor['Weixin'] =new_weixin new_infor['Addr'] =new_addr#add a dictionary to the listCard_infors.append (new_infor)#add a dictionary element to the list with the Append () function #print (card_infors) #for testdefdele_card_infor ():"""used to delete a business card"""Dele_name= Input ("Please enter the name you want to delete:")#Enter the name of the person you want to deleteFind_flag = 0#default indicates no found forTempinchcard_infors:ifDele_name = = temp["name"]: Find_flag= 1#indicates that the person to be deleted is found and the value of Find_flag is modified to 1Card_infors.remove (temp)Print("Delete Success! ")#use the Del function to remove a dictionary element from the list, and delete the first one only if the duplicate name Break ifFind_flag = =0:Print("No information for people you want to delete ....")defmodify_card_infor ():"""used to modify a business card"""Modify_name= Input ("Please enter the name of the person you want to modify:")#Enter the name of the person you want to modifyFind_flag = 0#default indicates no foundModify_flag = 0#determine if the modification was successful and the default modification failedSign =0 forTempinchcard_infors:sign+=1ifModify_name = = temp["name"]: Find_flag= 1Print("1. Change of name")#Print Modify Menu Print("2. Modify QQ") Print("3. Modify Weixin") Print("4. Modify the Address") Print("5. Exit to modify the system") whiletrue:num2= Int (Input ("Please enter the number of the information you want to modify:"))#Enter the number that corresponds to the modification ifNum2==1: Card_infors[sign-1]["name"] = input ("Please enter the correct name you want to modify:")#Modify the corresponding information under the corresponding revision numberModify_flag = 1elifnum2==2: Card_infors[sign-1]["QQ"] = Int (input ("Please enter the correct QQ you want to modify:")) Modify_flag= 1elifNum2==3: Card_infors[sign-1]["Weixin"] = Int (input ("Please enter the correct weixin you want to modify:")) Modify_flag= 1elifNum2==4: Card_infors[sign-1]["Addr"] = input ("Please enter the correct address you want to modify:") Modify_flag= 1elifNum2==5: Break Else: Print("input Error, please re-enter:") ifModify_flag = = 1:#determine if the modification was successful Print("modified successfully! ") Break Breakdeffind_card_infor ():"""used to query a business card"""Find_name= Input ("Please enter the name you want to find:")#Find by nameFind_flag = 0#default indicates no found Print("The information for the person you are looking for is:")#Print the information for the corresponding name Print("name \t\tqq\t\t\t\t\t address") forTempinchcard_infors:ifFind_name = = temp["name"]: Print("%-12s%-12s%-12s%s"% (temp['name'],temp['QQ'],temp['Weixin'],temp['Addr']))#oops, I wanted to use \ t horizontal tab, but the effect is not what I think, so I can only use this way of left alignmentFind_flag = 1#means found. ifFind_flag = = 0:#determine if you have found Print("I didn't find this guy. ╮ ( ̄▽ ̄) ╭ ....")defshow_all_infor ():"""Show All business card information""" Print("name \t\tqq\t\t\t\t\t address")#Print everyone's information forTempinchcard_infors:Print("%-12s%-12s%-12s%s"% (temp['name'],temp['QQ'],temp['Weixin'],temp['Addr']))defMain ():"""complete control of the entire program"""Print_menu ()#1. Print function Tips whileTrue:num= Int (Input ("Please enter the operation number:"))#2. Get the user's input ifNum==1:#3. Perform the corresponding function according to the user's dataadd_new_card_infor ()elifnum==2: Dele_card_infor ()elifNum==3: Modify_card_infor ()elifNum==4: Find_card_infor ()elifNum==5: Show_all_infor ()elifNum==6: Break Else: Print("input Error, please re-enter") Print("") Main ()#calling the main function
Python Practice-Business card management system (add, delete, find, modify)