7(iii)
Write a Python program that performs the following operations on a tuple:
- (a)Create a tuple with the elements: (5, 10, 15, 20, 25).
- (b)Access and print the element at index 2.
- (c)Convert the tuple into a list.
- (d)Append the integer 30 to the list.
- (e)Convert the list back into a tuple.
- (f)Print the final tuple.
Show SolutionHide Solution↓
numbers_tuple = (5, 10, 15, 20, 25)
element = numbers_tuple[2]
print("Element at index 2:", element)
numbers_list = list(numbers_tuple)
numbers_list.append(30)
final_tuple = tuple(numbers_list)
print("Final tuple:", final_tuple)
Element at index 2: 15
Final tuple: (5, 10, 15, 20, 25, 30)