100% found this document useful (1 vote)
901 views

Tuple Worksheet

The document contains questions about tuples in Python. It includes questions about creating and manipulating tuples, accessing tuple elements, tuple methods and functions, nested tuples, unpacking tuples and more. Example code and expected outputs are provided for many questions.

Uploaded by

Soumo Protim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
901 views

Tuple Worksheet

The document contains questions about tuples in Python. It includes questions about creating and manipulating tuples, accessing tuple elements, tuple methods and functions, nested tuples, unpacking tuples and more. Example code and expected outputs are provided for many questions.

Uploaded by

Soumo Protim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

RiT-COIMBATORE

CLASS:XI TOPIC:TUPLE

SUB: COMPUTER SCIENCEJ083] Fac.Code: IRN

Q1. What do you mean by Tuple in Python?

Q2. Write a statement to create an empty tuple named Tl'.

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]

Q5. Write a statement to create tuple T1 with single element.

Q6. Write the output of the following code:

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)

print T1) (1, 2, , 4.5,6,1,8)


print(T1 *2)
print/T1+ T1) 2,3.4,s,6.1,2,),,, 4, s,6, 1, 8)
printflenT1) * 2)

(1,2,B. 4,s,b.7.8,1, 2,3,4,5, b, 1,2)


09. Write a statement to create tuple Ti with the following data.

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)

Q13. Which error is returned by the following code:

T1 =(1, 2, 3, 4, 5, 6, 7, 8) Indax Oo hu plu ou ot o n g


printT1[15|)

two differences between Tuple and List.


Q14. Write

Q15. Write a statement in python to concatenate the given tuples.

T1 = (1, 2, 3)
T1+ 72
T2 (5, 6, 7)

Q16. Write the output of the following code


T1 (45, 67, 98)
T1 T1 +(1, 2, 3)
printfT1)
(u5.67,98, 1, 2.3)
Q17. Write the output of the following code:
T1 (45, 67, 98)
T1 T1*3
printT1) (45,61,98.45.b1,98,4S,67, 98
Q18. Write the output of the following code:

T1 (45, 67, 98)


T2 (145, 67, 98))
printfT1 in T2) FoJbc

print(45 in T2) T5us


print(45 in Tl) T5uus
printT1+ 12) (4, 67,98, 4S,61,96)

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 :

T1 23, 324,2, 12, 23, 7,9, 10, 23)


riatenTY+ TIF1) 3-
ritTITicoaat23)+ len(T1) 5
TlotT1{6)
itTLeousttmarT1
Q27. Wr the outpat oé the biowing:
1
3,32, 4, 5,2, 12, 22, 7,9, 10, 23
pr inTiy

Q28 rie the output of the Soilowing:


71 ( B o c Cicbet, Teotali)
ritme1
priainTi

TUPLE-WORKSHEETJN Page 3
Write the output of the following:
1 = (Raman', Ram', Ramaiya)
printmax(T1})
printtminTI}

Q30. Write the output of the following:

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)

Q31. Write the output of the following:


T1 = (23, 32, 4, 5, 2, 12, 23, 7, 9, 10, 23
printfsum{maTi) +min(Ti}})

Write a program to accept three numbers from the user and insert it at the end of given
Q3
Tuple T1.

T1 (23, 32, 4, 5, 2, 12, 23, 7, 9, 10, 23)

Q33. What type oferror is returned by folowing statement


>>(a,b.c.d) (5, 6, 8) o e a o : rot erogh vo npouk

Q34. Write the output of the following code :

>>>tname, rollBo, subjeet) ="'Anil",9, "Cs)


>>> nanme

Q35.Predict the output:

T-1,2,3)

del T

print)

Q36. What do you mean by Nested Tupie? Give one example

037. Write a statement to print 30 from the given tuple.

a rSeventy, |1, 2, 31, (20, 30, 40), "Eighty)

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)

Expected oUTPUT: BOOK


Q43. Write a program to remove a number (accepted from the user) from the given tuple T1 =
(12, 15, 18, 21, 24, 27, 30)

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

Q45. What do you mean by Packing Tuple? Give Example

Q46. Write one similarity between Tuples and String.

Q47. Write the output of the following:

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|)" ,

6. printT1I5:) I23, 43), s )


7. print(Ti.index("A")

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))

Q50. Write a program to store the detail Roll


( number, Name, Section) of three students in a
tuple. Accept all data from the user.

SAMPLE oUTPUT:
((1, 'Amita', '®'), (2, 'Sunita, 'C), (3, Daya, 'A')

Q51. Write a program to accept roll number from and


user display it's detail from given tuple
Det-((1, 'Amita', B), (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 (23, 45, 87, 45, 67, 43, 23, 12)


Q54. Write a program in python to display the sum of all even numbers and odd numbers
separately from the tuple given below

T1 (24, 45, 87, 46, 67, 44, 23, 12)


Q55. Write the output of the following

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

T1 (1,2, 3, 'A', B', 4, 'Sun)


959. Write a program to find the sum of marks of all students stored in the given tuple.

T1 (("Suman", 75),.(Glory" , 35),("Ravi",50))


Expected Output is: 160

Q60. Write the output of the following


T1 =
(1, (2, 'a"'), (3, 'b', 'e), (7, 'd', 'e, 'T})
printlen(T1))4
print(T1[1J[o]) 2

print7 in T1[3]) T

print(T1.index(1))
printlen(T1[3]})
printT1T1[2][O), 'd, e', )
Q61. Write the output of the following

T1 (1,2, 'a, 13, 'b', 'c, (7, 'd', 'e', TM


printlen(T1)) 2

printyT1[1]}o)
print(7 in T1[1]) F abx
printT1.ndez(1))
printlen(Tiji) 3

print(T1[Tijo) (2. 'a', (


, (7,'d'.'e', '*)))
Q62. Write the output ofthe following

T1 (1,(2, 'a") *2)


print(T1) (, (2.'o', 2, o ))
printlenlT1))

printT1[111) o

prlatjlen(Ti{1)

TUPLE-WORKSHEET[IRNJ Page 7
63. Write the output of the following:
T1 = (1, (2, '*')) *2

print(T1), (2.'a), (2.o


printlen(T)
print/T1[1]|) a

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)

Q67. Write the output of the following:


Ti = (1, 2, 3, 4)

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

W E iTymt mE i è s d pies ofa tupie in ncreasing


order and store them

( 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
=

Ege Ouge: 169. 49, 81

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)

Expected Output: 1, 2, 3, 4, 5, 6, 7,9, 11


Q76. Write a program to store the sum of all sub tuples of given tuple into a new tuple. for
example
T1 =
(1, 2, 3), (45, 23), (98, 34, 67),(34, 56, 78, 9)) #Original Tuple d anusd
T2 (6, 68, 199, 177) * New Tuple

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:

»S 1,(2,3,4,5), 51, (61,71)


>>>len(S)4
>»S[2:3]S
>S-1}0] 61
>type(S) Jass'tuple

8 4 . Predict the output:

T-(1,2,4,3,8,9)
IT] for I in range(0,len(T),2)]

85.What will be the output ofthe following code snippet?

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

3T= a,4,6,8, 10)

4 uplu (LI)

5 . a - Cq)_

Lsh_aa mtabla _ia pythod


opeyahou
betey fox erfomm
immutoblu q*ho 03u appopiote for
essingeluman

9 en): i mathad atu h Juno th of h


up
Sadaz un ( t p l )

count O: Thiamthod uturn ha tount of a


paaiuloa slanmntin m hapl
Sequnu_namu> count ( ob ject )

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

( 20, "Rashid &


tup
A
uted tupl Anushi",8s),
"Anushi"
"Amui90. "9o) (01,
(101.
s-((10
18,55)
12,
(12, 17 8, 2S,19,
("ender_numbey ")
numbey")
41T inputener

n int (n))
couwnt

Paint
I

2.T("B0 "o "o""K")

jon)_
AGE

a i n t (st)

24, 21,
3o)
2.15. 18.21, loJumou:

43 T1 endter
numbea

int Gnput ("


e
L i s t(T)
L u O e (el)
T tuplu ().
p a i n (T1)
you wont: ")
fuund D
paintCelumunt not
or innuHaluzin9
mLa ouaig
44 Unpadeing hu valu of huple
tuple
individual vasraklu rom
T (2,46

paund (A)

pund

rom individua vau is


45 uoking a hupl
allud paceing o hup
E 2, b
mmdol.
4b.BoH upl q staunqs

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-----

51 dat= (L'Amita, '8), (2, 'Sunita'. 'c). (3, Daya


YN int Gnput (" entey soll nmber "))
R O
o r i n rang (3):
Yn ddlillo]:
pun (dad Li1)
R=L
buak
O:
pain ucod not owrd

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)_

53T-(23 us, 845.3s, a, 23, 12


T = t a soted T)
Paunt (JIl-2])

54 = (24, 9s81 4b, 67 4Y 23, 12)


Se o
sO- O
o iin Ti:
2 0
Se s se +
ebe
so= o t i
pan Sum of even um be s se
put Sum ot odd numbeu is: so)
56 n= ind Cinput " Enter a y umber

t + (n1 i,)
pud (t)

51Stx inpud (" Enter stoung


I tuplu (sty)
paunt (I1)

58 Ts G,2,3, 'A8,4,'sun')_
S=O
foYiin Ti:
isty i). is diqit O'
S= St ii
Pnint s)

T ("suman" 15) C GloayL3S),(Rav, 50)D


SO
o in iL1)
S S+ il]_
pird CSum s)

10 n id Cinput (" enter umber: ")

OY i in1onqa( , nl+ ) :
i n . i = O:
1-++G,)

1T(1,2,3),45,23), (98,34,61)
T2(

T2-12+ (tuplu (sog ted i),


purd (12)
T2T1 (t1, 2,3), (4s, 1). (98, 34, 672, (34, S6
T2
for i in TL
12- 12 (un li)2)
Paunt(12)

13. T (12.13. 22.1.9. b6. 4)


fov in T

paunn ' 2 , ed

T (2,3. 9, 5.6)
T2 (3. s.1.9, 112
for iin T1
i n12
paint G, end

S T (12, 3.4, .b)


12 35.19)_
T3-T
for i in 12
iiinot in Ti:

:G2 Gs23) (Qs 34,61),(34, 5 18


oriin I
I2:12+ (sum (i),)
paint (T2)

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

irds (ms (T2)


ird12
paunt (11Lird))

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)

You might also like