Skip to content

Write a python program to find Largest and Smallest Element in a Dynamic Tuple

Class 11th IP (065)

Write a python program to find Largest and Smallest Element in a Dynamic Tuple

SOLUTION..

t = () while True: print("\n--- Tuple Menu ---") print("1. Create Tuple") print("2. Display Tuple") print("3. Find Largest & Smallest Element") 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 = int(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: largest = t[0] smallest = t[0] for num in t: if num > largest: largest = num if num < smallest: smallest = num print("Largest Element:", largest) print("Smallest Element:", smallest) elif choice == 4: print("Program terminated") break else: print("Invalid choice")