Tuple Worksheet
Tuple Worksheet
CLASS:XI TOPIC:TUPLE
Q3. Write a statement to create a tuple T1' containing first five even numbers.
Q4. Write the code to convert the given list L1 to tuple. Ll = [1, 2, 3, 4, 5]
T1 (4)
printtypeTI)) das ind
Q7. Write the output of the following code :
T1 4,5,6
print/type(T1}) asstuple
Q8. Write the output of the following code :
T1 = (1, 2, 3, 4, 5, 6, 7, 8)
1, 4, 'CS, TP, 5
, 4 'ce ' e
Q10. Write the output of the following code
T112,3, 4, 5, 6,7, 8)
print/Ti[o})
print/T1f-1)
print(T1[2+3])
print(T1[4 1])
print/T1[7%2])
TUPLE-WORKSHEET[IRN Page 1
pin (tup)
Write the output of the following :
1 =(1, 2, 3, 4, 5, 6,7, 8)
print(Tl[:}) (1, 2, 3,,5,6,1,8 )
print(T13 :}) (4, 5, 6,1.8)
print(T1[: 4})_1, 2, 3,4)
print(T1-2:-5])
Q12. Write the output of the following:
T1 = (1, 2, 3 , 4 , 5, 6, 7, 8)
print(T1[1::2]) (2.4, 6 , )
print(T1[-1:-5:-2]) ( 8. 6)
print T1[:: -1) (8,7, 6,5,4,3, 2,1)
print(T1[:7:2) ( 1,3,5.7)
T1 = (1, 2, 3)
T1+ 72
T2 (5, 6, 7)
TUPLE-WORKSHEET[IRN] Page 2
paint Gtup)
Q19. xpiain the following functions in reserence to Tuple in
Python.
1. len)
2 counti
Q20 Write a program to accept five mumbers from the user and store it in
a tuple T1'.
Q21. Write a program to
accept fve fruit name from the user and store it in a
tuple F1'.
Q22. Wrie a program to store n'
umber of sports in a tuple S1'.
Accept n' from the user)
Q23 Consider the following
tuple
and write the code for the
following statements:
Ti (12. 3, 45,
Hockey, 'Anil", (a, b))
Ds the first eement of T1
Displ the last element of "T1'
T1' in revee order.
Dispay AaT from tuple T1'
e
Dispry from tuple T1'
Q24. Wrie the output
of the folowing:
Sor i in
tpleSHLAt
Q25. Wrie the autput af
the foliowing
>>»7intupief 123456789)
»Tipie"123456789)5
Q26 We the output of the following :
TUPLE-WORKSHEETJN Page 3
Write the output of the following:
1 = (Raman', Ram', Ramaiya)
printmax(T1})
printtminTI}
T1 =
(23, 32, 4, 5, 2, 12, 23, 7, 9, 10, 23)
printsorted(T1)
printtsorted(T1{2: 7
printTl.index(23))
printTi.index{23, 3, 9)
Write a program to accept three numbers from the user and insert it at the end of given
Q3
Tuple T1.
T-1,2,3)
del T
print)
TUPLE-WORKSHEET[IRN] Page 4
pun tup)
variables.
Q38. Write a statement to unpack the following tuple into 3
n3)(bo,10 20)
60, 70, 80)
Q39. Write a program to swap the values of given tuples.
T1 A", E)
(3 pr(12
T2-134,655
Q40. Write the output of the following code:
T1 ATE.DIC)
T U y - P T o ) ,
printT1))
041.Write a program to print the frequency ofa number accepted from the user in given tuple
T1 -(12, 17,
18, 25, 19, 12, 18, 5)
42. Write a program in python to concatenate all the characters of given tuple. T1 = (B', 'O,
O', K)
SAMPLE EBoTION
pe
ple t t
after removing element is :(12, 15, 18,
24, 27, 30)
Q44. What do you mean by Unpacking
Tuple? Give example
T1 (2,'Apple, 6)
printimax(T1)
Q48. Consi the given tuple and write the output of given statements: T1 =
(1, 23, 4, 5, "A",
rC, D),. (23, 45), 45)
printflenri) 2
print(T1.index(45))
printfT1.count{45))
printT1{5102)
5. printT1{5|)" ,
rUPLE-WORKSHEET{IRNJ
Page 5
8. printtT1{-1:-7: -2])
9. printT1{4]+ T5|)
10.printlmaz(tl}) >
Q49. Write the length of following tuple:
T1 (1,/2,3),((34,56),45,67),39))
SAMPLE oUTPUT:
((1, 'Amita', '®'), (2, 'Sunita, 'C), (3, Daya, 'A')
Q52. Write a program to accept five numbers from the user and store these numbers in a tuple.
Display the following from tuple
1. Largest number
Smallest number
3. Sum of all numbers
4. Average of all numbers
Q53. Write a program in python to print the second largest element in tuple given below
T1 ("Amit", "Sumit")
T2 "Sumit", "Amit"
T3 "Amit", "Sumit"
print{T1=-T2) Fane
print/T1==T3)
Q56. Write a program to accept a number from the user and store first 10
in a tuple for example:
multiples of number
SAMPLEoUTPUT:
Enter any number:4
Tuple(4, 8, 12, 16, 20, 24, 28, 32, 36, 40)
Q57. Write a program to accept a string from the user and convert it into
tuple. for example
SAMPLEoUTPUT:
Enter any String: tuple
Tuple ('t, '7, p, 7,'e)
TUPLE-WORKSHEET[IRN
Page 6
pin tup)
958. Write a program to display the sum of all the numbers in a given tuple
print7 in T1[3]) T
print(T1.index(1))
printlen(T1[3]})
printT1T1[2][O), 'd, e', )
Q61. Write the output of the following
printyT1[1]}o)
print(7 in T1[1]) F abx
printT1.ndez(1))
printlen(Tiji) 3
printT1[111) o
prlatjlen(Ti{1)
TUPLE-WORKSHEET[IRNJ Page 7
63. Write the output of the following:
T1 = (1, (2, '*')) *2
printlen(Ti[i)
print(T1.count(1))
printT1.index( 1})
Q64. Write the output ofthe following
T1 = (a')* 3
T2 (a',)*3
print(T) aG
printitype(T1})< closs st
printlen(T1})
printT2) )
printtype(T2)) uple'
printlen(T2})
Q65. Write the output of the following:
T1 = "Spider Man:No Way Home"
T2 (T1.split)
print/T1) seder Mon no woy hom
printttype(T1}) < dass ' s t r >
printlen{T1)) 22
print(T2) Spidet, Mon NO.'way, P o m j
print(T2[0JJO] + T2[1ION SM
printlen(T2))
Q66. What type of error is returned by following code :
T1 = (1, 2, 3, 4)
T2 (4, 5, 6) ype eYO
print(T1 T2)
print(T1 *3)
print(T1 *(3))
,2,3., 1,2 3. ,1,2,3.)
print(T1) * 3)
(1,2.3,,1,2 3,, 2,3,4)
, 2 3 . 4, 1,2 3,u, ' 2 . 23. )
print(T1+(3,)) (,2,3.4. 3)
TUPLE-WORKSHEET[IRN] Page 8
paind tup)
t e te ungut af e iilewin
E
T mD RI Tumer i n e
e r and creara upe oontaining all factors
( 3. 3 5 . 3467.SS)
#New Tpie
g m 1 u e è ygè fdsubtupies ofa tupie into a new
tuple. for example
2 3. 5 3
s 674, S6 7S. 9} *Origins Tuple
2224# New Tpie
e a
gmDmsqur d l oii numbers of a tupie.
TI 12 13
227.9. 66
=
m a
Tgmtprirt the cummon eiements of given tupies :
T12 34,56
2 5 . 7,9. 11
Egee Ooupur: 3 55
UPLEWOBKSAEET|RN
Page 9
Write a program to find the union (Common element include once) of given tuples:
( 1 , 2, 3, 4, 5, 6)
T2 (3, 5, 7, 9, 11)
077. Write a program to store the maximum value of all sub tuples of given tuple into a new
tuple. for example
Ti ((1, 2, 3), (45, 23), (98, 34, 67),(34, 56, 78, 9),"A", "B", "c)
#Original Tuple
T2 (3, 45, 98, 78, c) #
New Tuple
978. Write a program to display the longest sub tuple from the given tuple.
Ti -(1,2, 3), (45, 23), (98, 34, 67), (34, 56, 78, 9) #
Original Tuple
T2 (34, 56, 78, 9) #
New Tuple
Q79. Write a
program to display names starting from vowel from the given tuple.
T1 (Amit", "Ram", "Esha", "Harry)
Q80. Write a
program to print the length of all names in a given tuple.
T1 ("Amit", "Ram", "Esha", "Harry")
Expected Output: 4, 3, 4, 5
Q81. What is the purpose of following operators in reference to tuples.
a)
b)
c) in
TUPLE-WORKSHEET[IRN]
Page 10
pi Ctup)
Q82. Match thefollowing
Functlons Descriptioon
Returns the length of the tuple. G
max()
Returns the index
value of element in tuple.
min
Returns the largest element in tuple. O
count(
Returns the smallest element in tuple. 2
index(
Returns the frequency of an element in tuple.
len()
Tuple Questions in Python
Q83. Write the output ofthe following:
T-(1,2,4,3,8,9)
IT] for I in range(0,len(T),2)]
inittuple-)
printinit
tuple. Jen 0) o
TUPLE-WORKSHEET[IRN Page 11
Success
DATE-- - ---- --
PAGE
wed tostoz a
Th o huasesequunu
of tupe Tuple i pnOn
u p l o t valus an
au immutable.
2 T tupl
4 uplu (LI)
5 . a - Cq)_
20 pe evo titps
up = )
whi (i<5):
nint inpu ender umber:
tup hup t (n,)
i=it
paud tup)
D4TE
PAGE
21 F O
i =o
whiu G <5):_ ")
Center fruut nomu
f a u i tE inpt
F F+ (fruut
it
pzuni (F_
w a n t : "y
spoTA do you
maru
22S O C Ho
unput
n = int n o m : " )
("Enter
io
w h i l u i < o :
I n p t
Sport (sport,
)_
St
S
23)
Paunt (S) 910
23,7,
4 S 2 1 2 ,
23, 32,
TI
(3): number " )
32 Enter
("
rongi
iin
n l = i n tCinput
for
t t t (nL)_
T TL+t
p i n t ( T ) _ .
u p l 1 1s
al
a ll
ld os aa
d as
anothu
are tupla 5
inside
n int (n))
couwnt
Paint
I
jon)_
AGE
a i n t (st)
24, 21,
3o)
2.15. 18.21, loJumou:
43 T1 endter
numbea
paund (A)
pund
50 dat=C)
allid a
imp =(
a for in 1anqa8)
Ynin Goput enter Yoll number:
"Rashid
20,
), ( nau)2
nm input C entey
sec iApud C enuey sechion :")
tmp (Gn, nMsec)
dit di +(tmp.)
Punt ( dat)
DATE
PAGE-----
5 2 t C)
for i in rangA (5)i
nl= iadt Gn put(" fntey umbe 4
- t + (nl,)_
pankC angest_umber is maz(t))
paint smallut number is un t))
punt Ove0QR is Sum (t)5)_
t + (n1 i,)
pud (t)
58 Ts G,2,3, 'A8,4,'sun')_
S=O
foYiin Ti:
isty i). is diqit O'
S= St ii
Pnint s)
OY i in1onqa( , nl+ ) :
i n . i = O:
1-++G,)
1T(1,2,3),45,23), (98,34,61)
T2(
paunn ' 2 , ed
T (2,3. 9, 5.6)
T2 (3. s.1.9, 112
for iin T1
i n12
paint G, end
1T - ((2.3), Gs.23)G834.
T2 C 61) 61) (34,S6.
(34. S6118.
O 10 T
T2= 12+(max(),)
purd 2 ) E2
(31.35. 12
512
(42,31.
231.
(t2.3),L4s.
2T
i o i n AEOU Geiau
T1-CAm on Esna.
80
torin
31) T ( cpear
1.2.3)+G5
hupl
1,2.3)'3
12.31.2.3L2.
auuid
i 1,2.2)