Mini Project on Contact Book in python

Certainly! Creating a basic contact book project in Python using dictionaries is a great way for beginners to practice their skills. Below is a simple implementation:

def add_contact(contacts, name, number):
    if name in contacts:
        print("Contact already exists!")
    else:
        contacts[name] = number
        print("Contact added successfully!")


def remove_contact(contacts, name):
    if name in contacts:
        del contacts[name]
        print("Contact removed successfully!")
    else:
        print("Contact not found!")


def display_contacts(contacts):
    if contacts:
        print("Contacts:")
        for name, number in contacts.items():
            print(f"{name}: {number}")
    else:
        print("No contacts to display.")


def main():
    contacts = {}

    while True:
        print("\nContact Book")
        print("1. Add Contact")
        print("2. Remove Contact")
        print("3. Display Contacts")
        print("4. Quit")

        choice = input("Enter your choice: ")

        if choice == "1":
            name = input("Enter contact name: ")
            number = input("Enter contact number: ")
            add_contact(contacts, name, number)
        elif choice == "2":
            name = input("Enter contact name to remove: ")
            remove_contact(contacts, name)
        elif choice == "3":
            display_contacts(contacts)
        elif choice == "4":
            print("Exiting...")
            break
        else:
            print("Invalid choice! Please enter a valid option.")


if __name__ == "__main__":
    main()

This code provides a simple command-line interface for managing contacts. You can add, remove, and display contacts using this program. It stores contacts in a dictionary where the keys are the names of the contacts and the values are their corresponding phone numbers.

To run this program, simply copy the code into a Python file (e.g., contact_book.py) and execute it with a Python interpreter (python contact_book.py).

Watch Now:- https://www.youtube.com/watch?v=4sEfkbqDWJM&t=68s