Sitemap

Member-only story

Building a Simple Phonebook Application in Python

3 min readJul 17, 2024

--

Introduction

Creating a phonebook application is a great way to practice fundamental programming concepts such as loops, conditionals, functions, and error handling. In this article, we will build a simple phonebook application that allows users to add, find, and delete contacts. Let’s dive in!

Understanding the Requirements

Our phonebook application will start with an empty state and provide the following functionalities:

  1. Find Phone Number: Retrieve a contact’s phone number.
  2. Add Phone Number: Add a new contact with a phone number.
  3. Delete Contact: Remove a contact from the phonebook.
  4. Terminate: Exit the application.

Designing the Solution

We will use a dictionary to store the phonebook, where the keys are contact names and the values are phone numbers. The application will continuously prompt the user for input until they choose to terminate the program.

Implementation

Let’s start coding our phonebook application:

def find_contact(phonebook, name):
if name in phonebook:
print(f"{phonebook[name]}")
else:
print(f"Couldn't find phone number of {name}")
def add_contact(phonebook, name, phone_number):
if not phone_number.isdigit():
print("Invalid…

--

--