Member-only story
Building a Simple Phonebook Application in Python
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:
- Find Phone Number: Retrieve a contact’s phone number.
- Add Phone Number: Add a new contact with a phone number.
- Delete Contact: Remove a contact from the phonebook.
- 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…







