Computer Science
Write a program to input any values for two tuples. Print it, interchange it and then compare them.
Python
Python Tuples
3 Likes
Answer
tuple1 = eval(input("Enter the first tuple: "))
tuple2 = eval(input("Enter the second tuple: "))
print("Original Tuples:")
print("Tuple 1:", tuple1)
print("Tuple 2:", tuple2)
tuple1, tuple2 = tuple2, tuple1
print("\nSwapped Tuples:")
print("Tuple 1 (after swapping):", tuple1)
print("Tuple 2 (after swapping):", tuple2)
if tuple1 == tuple2:
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.
Answered By
1 Like
Related Questions
A list Num contains the following elements:
3, 25, 13, 6, 35, 8, 14, 45
Write a program to swap the content with the next value divisible by 5 so that the resultant list will look like:
25, 3, 13, 35, 6, 8, 45, 14
Write a program to accept values from a user in a tuple. Add a tuple to it and display its elements one by one. Also display its maximum and minimum value.
Write a Python program to input 'n' classes and names of class teachers to store them in a dictionary and display the same. Also accept a particular class from the user and display the name of the class teacher of that class.
Write a program to store student names and their percentage in a dictionary and delete a particular student name from the dictionary. Also display the dictionary after deletion.