How to Build a Simple Contact Book in Python
- Anubhav Somani
- Sep 3
- 2 min read

Simple Contact Book. This project is a great next step because it introduces you to using dictionaries to store and manage structured data, a fundamental concept in programming.
First, here is the explanation of how the project is built.
How the "Simple Contact Book" is Made
The Core Idea: The goal is to create a command-line program where you can add, view, and store contact information. This simulates a basic address book, but instead of saving to a file (an intermediate step), it will keep the contacts in memory while the program is running.
The Data Structure: A Dictionary: A dictionary is the perfect tool for this job. We'll use a main dictionary (e.g., contacts) to hold our entire contact book. The keys of this dictionary will be the contact's name (a string), and the values will be another, nested dictionary containing that person's details, like their phone number and email. For example: {'Alice': {'phone': '123-456', 'email': 'alice@email.com'}}.
Creating a Menu-Driven App: To make the program interactive, we need a main loop (while True) that continuously runs and presents the user with a menu of options:
Add a new contact
View all contacts
Exit the program
Handling User's Choice: Inside the loop, we'll use input() to ask the user to choose an option from the menu. We then use if, elif, and else statements to determine which action to perform based on their choice.
Organizing with Functions: To keep the code clean and readable, we'll break the logic into separate functions.
add_contact(contacts_dict): This function will ask the user for a name, phone, and email. It will then add this information as a new entry into the main contacts dictionary.
view_contacts(contacts_dict): This function will loop through the main contacts dictionary and print out each contact's name and their details in a nicely formatted way. It will also handle the case where the contact book is empty.
Exiting the Program: If the user selects the "Exit" option from the menu, the break keyword is used to terminate the while loop, and the program ends with a goodbye message.



Comments