What is the best way to construct a contact book in Python?

Photo by Miles Burke on Unsplash

What is the best way to construct a contact book in Python?

·

2 min read

In this article, I'll show you how to create a contacts book using Python.

  • A contact book is a database that stores information on a person's contacts, such as phone numbers, email addresses, and other contact information.

  • Creating a contact book is an excellent project for someone with moderate Python skills. We'll add contacts to the book and find them using the person's name, so this somehow ties up with the use of data structures and methods.

  • Making a contact book in Python would greatly assist you in demonstrating and improving your coding abilities.

Now let's look at how to use Python to develop a contact book algorithm.

  • In this part, I'll show you how to use the Python programming language to develop a basic contacts book for storing and retrieving information.

  • You may use it as a project to build the same technique on a database to store the contacts with a few adjustments.

To begin, we must collect contact information such as name, phone number, and other pertinent information.

  • Here, I'm taking it from 5 different contact users; if you want to update it, go ahead.
names = []
contact_no = []
num = 5

print("\n\t* Create Your Contact List *")
for i in range(num):
    Name = input("\nName : ")
    Contact = input("Contact No : ")
    names.append(Name)
    contact_no.append(Contact)
print("\n Name \t\t Contact No \n")

Now we'll save the user information in a table.

for i in range(num):
    print("{} \t\t {} ".format(names[i], contact_no[i]))

Then we'll make a search tool to provide the information that the user is looking for.

Search = input("\n Type the item you're looking for : ")
if Search in names:
    index = names.index(Search)
    Contact = contact_no[index]
    print("\nHere Your Search item : ")
    print(" Name : {} \n Conatact No : {}\n".format(Search,Contact))
else:
    print("\nSearched Item Not Found ! \n")

Let us have a look at the outcomes :

pt.png