Python to implement business card management system

Source: Internet
Author: User

——————————————————————————————————————————————————————

Want to master what knowledge, need in what to spend time, impetuous look, read that forget, plus learned, do not use, after a few days forgot to shut.

Apply. When you learn python, think about it, if it's a C + + programming implementation. Write over and over again, and learn again and again.

Tomorrow will thank you for your efforts today.

—————————————————————————————————————————————————————— Preface

The Python tutorials that you've seen before, really look at it yourself, Python's program can understand, but it's hard to implement. More difficult to implement some of their own code, looking for work reasons, their own seriously really read, knock code, and then saw the topic, want to learn the python commonly used data types to review. It took a little time for programming to happen. python implementation of the postcard management system can achieve the following functions: *****************
Business Card Management System

1. Add Business Cards

2. Remove Business Cards

3. Change Business Card

4. Query Business Card

5. Exit system

0. Show all business cards

Add business Card programming ideas first create a temporary templist variable, through the Templist.append () method, add, name, phone number, address and other information, and then append the Templist list to Mainlist in the list.

def incremem (alist):
    templist = [] 
    tempname = input ("Enter new business Card name:")
    templist.append (tempname)
    while True:
        tempphone = input ("Enter new contact mobile number:") 
        if Tempphone.isnumeric (): Break
        Else:print ("Input is incorrect, reenter")    
    Templist.append (tempphone)
    tempaddr = input ("Enter new contact Address:")
    templist.append (tempaddr)
    print (" Enter new contact information: "
    showlist (templist)
    alist.append (templist)
Note: Cell phone numbers are numbers, you can use the List.isnumeric () method to determine whether a pure numeric string, not return False Remove a business cardProgramming Ideas: First calculate whether is empty, if it is empty return, then locate the delete contact index value, and finally delete the contact through the Del () function.
def delmem (alist):
    i = 0
    if len (alist) = 0: 
        print ("No contact, please add a contact first.") ")
        return
    tempname = input (" Enter the contact to delete: ") for
    mumlist in alist:
        if Tempname!= mumlist[0]:
            i = = 1
  
   continue
        Else:
            showlist (Alist[i]) while
            True:
                tempin = input ("Delete this contact: Y (yes) \ t N (NO):")
                if Tempin = = "Y" or tempin = = "Y":
                    del (alist[i])
                    print ("delete succeeded.") ") 
                return elif Tempin = =" N "or Tempin = =" n ":
                    print (" Reenter contact. ") ")
                    Delmem (alist)
                return else:
                    print (" Input is incorrect, re-enter! ")                    
    if i = = Len (alist):
        print ("Enter the contact hot does not exist, please re-enter.") ")
        Delmem (alist)
  
Note: If the deleted contact does not exist, how to handle it. For mainlist traversal, each element is an element of a list structure. If the contact you want to delete is not equal to numlinst[0], continue, I will increase by 1. If you iterate through all, none, then i = Len (alist), then the contact person does not exist and re-enter. Change Business CardModify the business card, first locate and then modify.
def modmem (alist):
    i = 0
    if len (alist) = 0: 
        print ("No contact, please add a contact first.") ")
        return
    templist = input (" Enter the contact you want to modify: ") for
    numlist in alist:
        if Templist!= numlist[0]:
            i = = 1
  continue
        Else:
            tempinf = input ("Input modified Information:")
            if Tempinf.isnumeric ():
                numlist[1] = Tempinf
            else:
                numlist[2] = Tempinf
    If i = Len (alist):
        print ("entered incorrectly, re-enter.") ")
        Modmem (alist)
Note: the Is.numeric () method, the judgment, all is the number, then is modifies the telephone number, otherwise is the address. Find a business cardPosition first, then output. Note Analysis when there are no contacts
def locamem (alist):
    i = 0
    if len (alist) = 0: 
        print ("No contact, please add a contact first.") ")
        return
    templist = input (" Enter the contact you want to find: ") for
    numlist in alist:
        if Templist!= numlist[0]:
            i = = 1
  continue
        Else:
            showlist (numlist)
    if i = = Len (alist):
        print ("entered incorrectly, re-enter.") ")
        Modmem (alist)             
Complete pieces of the program
Def men (): Print ("\t*****************") print ("\ t card management system \ n") print ("\ t 1 add business card \ n") print ("\ t 2. Remove business card \ n") Print ("\ t 3. Modify business card \ n") print ("\ t 4. query business card \ n") print ("T 5. Exit system \ n") print ("\ t 0. Show all cards \ n") print ("\t****
    ") def Incremem (alist): Templist = [] Tempname = input (" Enter new business Card name: ") templist.append (Tempname) While true:tempphone = input ("Enter new contact mobile number:") if Tempphone.isnumeric (): Break Else:print ("Input is incorrect, Reenter ") Templist.append (tempphone) tempaddr = input (" Enter new contact Address: ") templist.append (tempaddr) Print (" Enter new
         Contact information: ") showlist (templist) alist.append (templist) def showlist (alist): Print (" Name:%s "%alist[0],\
    "Phone:%s"%alist[1], \ "Address:%s"%alist[2], "\ n") def Showmem (alist): If Len (alist) = 0:print ("no contact!") For mumlist in Alist:print ("First:%s"%mumlist[0],\ "Tel:%s"%mumlist[1], \ "Address:%s"%mumli ST[2], "\ n") def Delmem (ALIST): i = 0 if len (alist) = = 0:print ("There are no contacts, please add a contact first.")
            ") Return tempname = input (" Enter the contact to delete: ") for mumlist in Alist:if tempname!= mumlist[0]: i + 1 continue else:showlist (Alist[i]) while True:temp
                    in = input ("Delete this contact: Y (yes) \ t N (NO):") if Tempin = = "Y" or tempin = = "Y": Del (Alist[i]) Print ("delete succeeded.") ") return elif Tempin = =" N "or Tempin = =" N ": Print (" Reenter contact. ") ") Delmem (alist) return Else:print (" entered incorrectly, reenter                    
    !") if i = = Len (alist): Print ("Enter the contact hot does not exist, please re-enter.") ") Delmem (alist) def modmem (alist): i = 0 if len (alist) = = 0:print (" No contact, please add the contact first. ") ") Return templist = input (" Enter the contact you want to modify: ") for numlist in Alist:if templist!= Numlist[0]: i + 1 Continue else:tempinf = input ("Enter modified information:") if  Tempinf.isnumeric (): numlist[1] = tempinf else:numlist[2] = Tempinf if I = = Len (alist): Print ("entered incorrectly, re-enter.") ") Modmem (alist) def locamem (alist): i = 0 if len (alist) = = 0:print (" No contact, please add the contact first. ")
            ") Return templist = input (" Enter the contact you want to find: ") for numlist in Alist:if templist!= numlist[0]: i + 1 continue else:showlist (numlist) if i = = Len (alist): print ("Incorrect input, Re-enter.
    ") Modmem (alist) If __name__ = =" __main__ ": Mainlist = [] men ()
            While true:index = input ("Enter task number:") if not Index.isnumeric (): Print ("Enter index number (1-4):")
    Continue index = INT (index) #遍历名片 If index = = 0:showmem (mainlist)    #增加名片 If index = = 1:incremem (mainlist) If index = = 2:delmem (mainlist) 
            If index = = 3:modmem (mainlist) If index = = 4:locamem (mainlist) If index = 5: Print ("Exit the system.) ") Break




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.