SEP-PYTHON

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7

PART B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 PROGRAM B7 . . .

 
 
   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}")