Class 11th IP (065)
Write a Program to create a Dynamic Dictionary (Key–Value Input & Display)
SOLUTION..
data = {} while True: print("\n--- Dictionary Menu ---") print("1. Add / Update Element") print("2. Delete Element") print("3. Search Element") print("4. Display Dictionary") print("5. Exit") choice = int(input("Enter your choice: ")) if choice == 1: key = input("Enter key: ") value = input("Enter value: ") data[key] = value print("Element added/updated successfully") elif choice == 2: key = input("Enter key to delete: ") if key in data: del data[key] print("Element deleted successfully") else: print("Key not found") elif choice == 3: key = input("Enter key to search: ") if key in data: print("Value:", data[key]) else: print("Key not found") elif choice == 4: if len(data) == 0: print("Dictionary is empty") else: print("Dictionary Contents:") for k, v in data.items(): print(k, ":", v) elif choice == 5: print("Exiting program") break else: print("Invalid choice")


