Python Programming Examples Tutorial Index
Python File I/O Programs

This Python contact book program saves user input as a contact book description and retrieves it as search results. It is a fundamental program that shows how simple logic works using arrays, loops, and conditional statements.

Example:

An example of a Contact book in Python:

names = []
contact_numbers = []
num = int(input("Enter the total number of contacts you want to save: "))
for i in range(num):
    name = input("Name: ")
    contact_number = int(input("Contact Number: ")) 
    names.append(name)
    contact_numbers.append(contact_number)
print("\nName\t\t\tContact Number\n")
for i in range(num):
    print("{}\t\t\t{}".format(names[i], contact_numbers[i]))
search_term = input("\nEnter search term: ")
print("Search result:")
if search_term in names:
    index = names.index(search_term)
    contact_number = contact_numbers[index]
    print("Name: {}, Phone Number: {}".format(search_term, contact_number))
else:
    print("No records")

Program Output:

Enter the total number of contacts you want to save: 2
Name: Alex
Contact Number: 123456789
Name: Amara
Contact Number: 984321

Name                    Contact Number

Alex                    123456789
Amara                   987654321

Enter search term: Alex
Search result:
Name: Alex, Phone Number: 123456789