PART -B
#2.Write a Program to Demonstrate use of Tuples
# 1. Creating a tuple
# Tuples use parentheses ()
coordinates = (10.5, 20.2, 35.8)
fruits = ("apple", "banana", "cherry")
print(f"Coordinates: {coordinates}")
print(f"First fruit: {fruits[0]}") # Accessing by index
x, y, z = coordinates
print(f"Unpacked x: {x}, y: {y}, z: {z}")
try:
fruits[0] = "orange" # This will raise an error
except TypeError as e:
print(f"\nCaught expected error: {e}")
print("Explanation: Tuples are immutable; you cannot change an item once set.")
mutable_fruits = list(fruits)
mutable_fruits[0] = "orange"
new_fruits = tuple(mutable_fruits)
print(f"Modified tuple: {new_fruits}")