Python Basics (7)-Business card management system (simple storage, modification, deletion, viewing, etc.)

Source: Internet
Author: User

After learning some basic knowledge of python, this knowledge is synthesized, and the business card management system is realized, and the data can be changed and deleted.

The main idea is to put the business Card (information) into the dictionary, and then put the dictionary into the list, convenient for the increase and deletion check.

The code is as follows:

1 #-*-encoding:utf-8-*-2 #used to store business cards3Card_infors = []#an empty list4 5 defPrint_menu ():6     #Finish the Print function menu7     Print("="*50)8     Print("Business Card management system V0.01")9     Print("1. Add a new business card")Ten     Print("2. Delete a business card") One     Print("3. Modify a business card") A     Print("4. Query a business card") -     Print("5. Show All business cards") -     Print("6. Exit the system") the     Print("="*50) -  - defadd_new_card_infor (): -     #complete the Add a new business card +New_name = Raw_input ("Please enter a new name:") -NEW_QQ = Raw_input ("Please enter the new QQ:") +New_weixin = Raw_input ("Please enter a NEW:") ANEW_ADDR = Raw_input ("Please enter a new address:") at  -     #define a new dictionary to store a new business card -New_infor = {} -new_infor['name'] =new_name -new_infor['QQ'] =NEW_QQ -new_infor['Weixin'] =new_weixin innew_infor['Addr'] =new_addr -  to     #add a dictionary to the list +     Globalcard_infors - card_infors.append (new_infor) the  *     #print (card_infors) # for Test $ Panax Notoginseng deffind_card_infor (): -     Globalcard_infors theFind_name = Raw_input ("Please enter the name you want to find:") +Find_flag = 0#default indicates no found A      forTempinchcard_infors: the         ifFind_name = = temp["name"]: +             Print("%s\t%s\t%s\t%s"% (temp['name'],temp['QQ'],temp['Weixin'],temp['Addr'])) -Find_flag = 1 $              Break $     ifFind_flag = =0: -         Print("I can't find this guy.") -  the defShow_all_inf (): -     Globalcard_inforsWuyi     Print("name \tqq\tweixin\t address") the  -      forTempinchcard_infors: Wu         Print("%s\t%s\t%s\t%s"% (temp['name'],temp['QQ'],temp['Weixin'],temp['Addr'])) -   #print ("-------show--------") About  $ defModify_inf (): -     #Modifying Functions -     Globalcard_infors -Mod_name = Raw_input ("Please enter the name you want to modify:") A      forTempinchcard_infors: +         iftemp['name'] ==Mod_name: thetemp['name'] = Raw_input ("Please enter a new name:") -temp['QQ'] = Raw_input ("Please enter the new QQ:") $temp['Weixin'] = Raw_input ("Please enter a NEW:") thetemp['Addr'] = Raw_input ("Please enter a new address:") the             Print("-------Modification completed--------") the             return  the     Print("-------no man--------") -  in defDelete_inf (): the     #Delete a function the     Globalcard_infors AboutDel_name = Raw_input ("Please enter the name you want to delete:") the      forTempinchcard_infors: the         iftemp['name'] ==Del_name: the Card_infors.remove (temp) +              Break -     Print("-------Delete is complete--------") the Bayi defMain (): the     #complete the call to the entire module the Print_menu () -  -      whileTrue: the         #Get user Input thenum = input ("Please enter a selection:") the         ifnum = = 1: the add_new_card_infor () -         elifnum = = 2: the Delete_inf () the         elifnum = = 3: the Modify_inf ()94         elifnum = = 4: the find_card_infor () the         elifnum = = 5: the Show_all_inf ()98         elifnum = = 6: About              Break -         Else:101             Print("input error, re-enter")102Main ()#main function Execution

Python Basics (7)-Business card management system (simple storage, modification, deletion, viewing, etc.)

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: info-contact@alibabacloud.com 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.