Thursday, November 13, 2025

πŸ›️ Project: Mini Contact Book using Dictionary

 A contact book stores names and phone numbers.

We will use a dictionary where:

  • Key = Contact Name

  • Value = Phone Number


πŸ“Œ Project Code: Contact Book

# Simple Contact Book using Dictionary contacts = {} # Empty dictionary to store contacts while True: print("\n----- Contact Book -----") print("1. Add Contact") print("2. View Contact") print("3. View All Contacts") print("4. Delete Contact") print("5. Exit") choice = input("Enter your choice: ") if choice == "1": name = input("Enter name: ") number = input("Enter phone number: ") contacts[name] = number print(f"Contact '{name}' added.") elif choice == "2": name = input("Enter name to search: ") if name in contacts: print(f"{name} : {contacts[name]}") else: print("Contact not found.") elif choice == "3": if contacts: print("\nAll Contacts:") for name, number in contacts.items(): print(f"{name} : {number}") else: print("No contacts saved.") elif choice == "4": name = input("Enter name to delete: ") if name in contacts: contacts.pop(name) print(f"Contact '{name}' deleted.") else: print("Contact not found.") elif choice == "5": print("Exiting Contact Book... Goodbye!") break else: print("Invalid choice. Try again.")

🧠 What You Learn from This Project

✔ Creating and using dictionaries
✔ Adding key–value pairs
✔ Updating and deleting items
✔ Looping through dictionaries
✔ Simple user input handling

No comments:

Post a Comment

Python Viva Questions

  Basic Python Viva Questions 1. What is Python? Python is a high-level, interpreted, and object-oriented programming language used for w...