Programming Example

Write a program to input any two tuples and interchange the tuple values.

Solution

t1=tuple()
n=int(input("Total number of values in first tuple"))
for i in range(n):
    a=input("enter elements")
    t1=t1+(a,)
t2=tuple()
m=int(input("Total number of values in second tuple"))
for i in range(m):
    a=input("enter elements")
    t2=t2+(a,)
print ("Before SWAPPING")
print ("First Tuple",t1)
print ("Second Tuple",t2)
t1,t2=t2,t1
print ("AFTER SWAPPING")
print ("First Tuple",t1)
print ("Second Tuple",t2)
Output

Total number of values in first tuple3

enter elements10

enter elements20

enter elements30

Total number of values in second tuple4

enter elements100

enter elements200

enter elements300

enter elements400

Before SWAPPING

First Tuple ('10', '20', '30')

Second Tuple ('100', '200', '300', '400')

AFTER SWAPPING

First Tuple ('100', '200', '300', '400')

Second Tuple ('10', '20', '30')

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad