Python is indeed a language for zero-based programming enthusiasts to learn. python's programs can be understood, but it is difficult to achieve. This is a problem that almost every beginner who learns Python will encounter. Memory is better than bad writing. Applying knowledge to practical projects is the best way to remember.
After familiarizing ourselves with python's common data types, we can start to gracefully operate a small project to implement a business card management system.
It can achieve the following functions:
Business Card Management System
1. Add business cards
2. Delete business cards
3. Modify business cards
4. Search for business cards
5. Exit the system
0. Display all business cards
Add business cards
The idea of programming is to create a temporary templist variable, add, name, mobile phone number, address and other information through templist. Appnd () method, and then append the templist list list to the mainList list.
def increMem(aList): tempList = [] tempName = input("Enter the name of the new business card:") tempList.append(tempName) while True: tempPhone = input("Enter the new contact number:") if tempPhone.isnumeric(): break else: print("Enter incorrectly, re-enter") tempList.append(tempPhone) tempAddr = input("Enter the new contact address:") tempList.append(tempAddr) print("Enter new contact information:") showList(tempList) aList.append(tempList)
Be careful:
Cell phone numbers are all numbers, you can use the list.isnumeric() method to determine whether it is a pure digital string, not return False.
Delete business cards
Programming idea: first calculate whether it is empty, if it is empty to return, then first locate and delete the index value of the contact, and finally delete the contact through the del() function.
def delMem(aList): i = 0 if len(aList) == 0 : print("No contacts, Please add contacts 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("Whether to delete this contact: Y(yes)\t N(no) :") if tempIn =="Y" or tempIn == "y": del(aList[i]) print("Delete successfully!") return elif tempIn == "N" or tempIn == "n": print("Re-enter the contact!") delMem(aList) return else: print("Enter incorrectly, re-enter!") if i == len(aList): print("Input contact heat does not exist, please re-enter!") delMem(aList)
Be careful:
What if the deleted contact does not exist? For mainList traversal, each element is an element of a list structure. If the contact to be deleted is not equal to numLinst[0], continue, i increases by 1. If all of them are traversed, then i = len(aList), then judge that the contact does not exist and re-enter.
If you are still confused in the world of programming, you can join our Python Learning button qun: 784758214 to see how our predecessors learned. Exchange of experience. From basic Python script to web development, crawler, django, data mining, zero-base to actual project data are sorted out. To every Python buddy! Share some learning methods and small details that need attention. Click to join us. python learner gathering place
Modify business cards
Modify business cards, first locate and then modify
def modMem(aList): i = 0 if len(aList) == 0 : print("No contacts, Please add contacts first!") return tempList = input("Enter contacts that need to be modified:") for numList in aList: if tempList != numList[0] : i += 1 continue else: tempInf = input("Enter the modified information:") if tempInf.isnumeric(): numList[1] = tempInf else: numList[2] = tempInf if i == len(aList): print("Input error, re-enter!") modMem(aList)
Be careful:
is.numeric() method, judgment, is all digital, is to modify the phone number, otherwise it is the address.
Look for business cards
First locate, then output. Pay attention to the situation when there are no contacts
def LocaMem(aList): i = 0 if len(aList) == 0 : print("No contacts, Please add contacts first!") return tempList = input("Enter the contacts you need to find:") for numList in aList: if tempList != numList[0] : i += 1 continue else: showList(numList) if i == len(aList): print("Input error, re-enter!") modMem(aList)
Complete program block
//What I don't know in the process of learning can be added to me? python Learning Exchange Button qun,784758214 //There are good learning video tutorials, development tools and e-books in the group. //Share with you the current talent needs of python enterprises and how to learn python from zero foundation, and what to learn def men(): print("\t*****************") print("\t Business Card Management System\n") print("\t 1.Add business cards\n") print("\t 2.Delete business cards\n") print("\t 3.Modify business cards\n") print("\t 4.Inquiring Business Cards\n") print("\t 5.Exit System\n") print("\t 0.Display all business cards\n") print("\t*****************") def increMem(aList): tempList = [] tempName = input("Enter the name of the new business card:") tempList.append(tempName) while True: tempPhone = input("Enter the new contact number:") if tempPhone.isnumeric(): break else: print("Enter incorrectly, re-enter") tempList.append(tempPhone) tempAddr = input("Enter the new contact address:") tempList.append(tempAddr) print("Enter new contact information:") showList(tempList) aList.append(tempList) def showList(aList): print("Name: %s"%aList[0],\ "Telephone:%s"%aList[1], \ "Address:%s"%aList[2],"\n") def showMem(aList): if len(aList) == 0: print("No contact!") for mumList in aList: print("Name: %s"%mumList[0],\ "Telephone:%s"%mumList[1], \ "Address:%s"%mumList[2],"\n") def delMem(aList): i = 0 if len(aList) == 0 : print("No contacts, Please add contacts 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("Whether to delete this contact: Y(yes)\t N(no) :") if tempIn =="Y" or tempIn == "y": del(aList[i]) print("Delete successfully!") return elif tempIn == "N" or tempIn == "n": print("Re-enter the contact!") delMem(aList) return else: print("Enter incorrectly, re-enter!") if i == len(aList): print("Input contact heat does not exist, please re-enter!") delMem(aList) def modMem(aList): i = 0 if len(aList) == 0 : print("No contacts, Please add contacts first!") return tempList = input("Enter contacts that need to be modified:") for numList in aList: if tempList != numList[0] : i += 1 continue else: tempInf = input("Enter the modified information:") if tempInf.isnumeric(): numList[1] = tempInf else: numList[2] = tempInf if i == len(aList): print("Input error, re-enter!") modMem(aList) def LocaMem(aList): i = 0 if len(aList) == 0 : print("No contacts, Please add contacts first!") return tempList = input("Enter the contacts you need to find:") for numList in aList: if tempList != numList[0] : i += 1 continue else: showList(numList) if i == len(aList): print("Input error, re-enter!") modMem(aList) if __name__ == "__main__": mainList = [] men() while True: index = input("Enter the task number:") if not index.isnumeric(): print("Please enter the index number (1)-4): ") continue index = int(index) #Traversing business cards if index == 0: showMem(mainList) #Increase business cards 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