MENU
Question -

Write a program to input ‘n’ numbers and separate the tuple in the following manner.
Example
T=(10,20,30,40,50,60)
Tl=(10,30,50)
T2=(20,40,60)



Answer -

t=tuple( )
n=input(” Enter number of values:”)
for i in range(n):
a=input(“enter elements”)
t=t+(a,)
t1=t2=tuple( )
for i in t:
if i%2 == 0:
t2= t2 + (i,)
else:
tl=tl+(i,)
print “First Tuple”
print t1
print “Second Tuple”
print t2
Output:
Enter number of values: 10
enter elements 1
enter elements 9
enter elements 8
enter elements 5
enter elements 2
enter elements 3
enter elements 6
enter elements 4
enter elements 7
enter elements 10
First Tuple (1, 9, 5, 3, 7)
Second Tuple (8,2,6,4,10)

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
Any questions? Ask us!
×