Signup/Sign In

Contact Book Python Project

Contact Book Python Project

A contact book is a database that stores information about a person's contacts, such as phone numbers, email addresses, and so on. It's also referred to as the address book. I'll show you how to make a contact book using Python in this tutorial.

Using Python, create a Contact Book

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

As a result, constructing a contacts book in Python will greatly assist you in demonstrating and improving your coding abilities. You must build an algorithm that enables the user to record and discover any person's data while constructing a contacts book using Python.

Python's Contact Book

In this part, we'll show you how to use the Python programming language to develop a simple contacts book for storing and retrieving contacts. You may use it as a project to build the same technique on a database like MySQL to store the contacts with a few adjustments.

Now let's look at how to use Python to develop a contact book algorithm. By changing the code below, you can preserve additional information than only contact information:

Source Code for Contact Book Python Project

names = []
phone_numbers = []
num = 3


for i in range(num):
    name = input("Name: ")
    phone_number = input("Phone Number: ") # for convert to int => int(input("Phone Number: "))

    names.append(name)
    phone_numbers.append(phone_number)

print("\nName\t\t\tPhone Number\n")

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

search_term = input("\nEnter search term: ")

print("Search result:")

if search_term in names:
    index = names.index(search_term)
    phone_number = phone_numbers[index]
    print("Name: {}, Phone Number: {}".format(search_term, phone_number))

else:
    print("Name Not Found")

Output

Name: Aman
Phone Number: 8587******
Name: Akash
Phone Number: 9810******
Name: Kharwal
Phone Number: 9811******

Name                    Phone Number

Aman                    8587******
Akash                   9810******
Kharwal                 9811******

Enter search term: Aman
Search result:
Name: Aman, Phone Number: 8587******

Final Words

You must add three contacts before executing the above code, and then you will be prompted to search for a contact. Remember to search using the person's name, and feel free to edit the code to fit your requirements.



About the author:
Adarsh Kumar Singh is a technology writer with a passion for coding and programming. With years of experience in the technical field, he has established a reputation as a knowledgeable and insightful writer on a range of technical topics.