CBSE Class 11 Computer Science Question 71 of 88

Tuples and Dictionary — Question 36

Back to all questions
36
Question

Question 19

Write a Python program to input any values for two tuples. Print it, interchange it, and then compare them.

Solution
t1 = eval(input("Enter the first tuple: "))
t2 = eval(input("Enter the second tuple: "))

print("Original Tuples:")
print("Tuple 1:", t1)
print("Tuple 2:", t2)

t1, t2 = t2, t1

print("\nSwapped Tuples:")
print("Tuple 1 (after swapping):", t1)
print("Tuple 2 (after swapping):", t2)

if t1 == t2:
    print("\nThe swapped tuples are equal.")
else:
    print("\nThe swapped tuples are not equal.")
Output
Enter the first tuple: (5, 6, 3, 8, 9)
Enter the second tuple: (77, 33, 55, 66, 11)
Original Tuples:
Tuple 1: (5, 6, 3, 8, 9)
Tuple 2: (77, 33, 55, 66, 11)

Swapped Tuples:
Tuple 1 (after swapping): (77, 33, 55, 66, 11)
Tuple 2 (after swapping): (5, 6, 3, 8, 9)

The swapped tuples are not equal.
Answer