Class 11th IP (065)
Write a Python Program to Search an Element in a Dynamic Tuple
SOLUTION..
t = () while True: print("\n--- Tuple Menu ---") print("1. Create Tuple") print("2. Display Tuple") print("3. Search Element in Tuple") print("4. Exit") choice = int(input("Enter your choice: ")) if choice == 1: lst = [] n = int(input("Enter number of elements: ")) for i in range(n): element = input(f"Enter element {i+1}: ") lst.append(element) t = tuple(lst) print("Tuple created successfully") elif choice == 2: if len(t) == 0: print("Tuple is empty") else: print("Tuple:", t) elif choice == 3: if len(t) == 0: print("Tuple is empty") else: search = input("Enter element to search: ") found = False for item in t: if item == search: found = True break if found: print("Element found in tuple") else: print("Element not found in tuple") elif choice == 4: print("Program terminated") break else: print("Invalid choice")


