ASSIGNMENT
Q. 25
25.Write a menu-driven Python program to create a Phone Book using a dictionary. Key = Person Name Value = Mobile Number The program should: Add Contact Search Contact Update Contact Delete Contact Display All Contacts
# Menu-driven program to create a Phone Book using a dictionary phone_book = {} while True: print("\n========== PHONE BOOK MENU ==========") print("1. Add Contact") print("2. Search Contact") print("3. Update Contact") print("4. Delete Contact") print("5. Display All Contacts") print("6. Exit") print("=====================================") choice = int(input("Enter your choice: ")) if choice == 1: # Add Contact name = input("Enter person's name: ") mobile = input("Enter mobile number: ") phone_book[name] = mobile print("Contact added successfully.") elif choice == 2: # Search Contact name = input("Enter person's name to search: ") if name in phone_book: print("Mobile Number:", phone_book[name]) else: print("Contact not found.") elif choice == 3: # Update Contact name = input("Enter person's name to update: ") if name in phone_book: mobile = input("Enter new mobile number: ") phone_book[name] = mobile print("Contact updated successfully.") else: print("Contact not found.") elif choice == 4: # Delete Contact name = input("Enter person's name to delete: ") if name in phone_book: del phone_book[name] print("Contact deleted successfully.") else: print("Contact not found.") elif choice == 5: # Display All Contacts if len(phone_book) == 0: print("Phone book is empty.") else: print("\n========== ALL CONTACTS ==========") for name, mobile in phone_book.items(): print("Name:", name) print("Mobile Number:", mobile) print("-------------------------------") elif choice == 6: # Exit print("Program terminated.") break else: print("Invalid choice. Please try again.")


