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.


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: ")) 
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))
    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

Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram