12CS_ProgramBasedTest3_Answers
12CS_ProgramBasedTest3_Answers
LESSON – 9
ANSWERS / விடைகள்
WRITE THE OUTPUT OF THE FOLLOWING SNIPPETS. / பின்வரும் குறிமுறைகளின் வெளியீட்டை எழுதுக.
1) Write the number of elements in the following list:/ பின்வரும் பட்டியலில் உள்ள
உறுப்புகளின் எண்ணிக்கககய எழுதவும்:
..1..
5) Find the correct statement to add multiple elements to the list “Mylist=[2,4,6]”
/ "Mylist=[2,4,6]" என்ற List-ல் பல உறுப்புககளச் சேர்க்க பயன்படும் ேரியான
கூற்கைக் கண்டைியவும்.
7) Mylist = [ 2, 4, 6 ]
Mylist.insert(0,0)
Mylist.extend([8])
Mylist.append(14)
Mylist.insert(5,12)
i=-1
while i >= -7:
print(Mylist[i])
14
12
8
6
4
2
0
8) Mylist = [ 0, 2, 4, 6, 8, 10, 12, 12, 14 ]
del(Mylist[7])
del(Mylist[1:4])
print(Mylist)
[0, 8, 10, 12, 14]
9) Mylist = [ 0, 2, 4, 6, 8, 10, 12, 12, 14 ]
del(Mylist[7])
del(Mylist[1:4])
del(Mylist[0])
print(Mylist)
del Mylist
[8, 10, 12, 14]
..2..
10) Mylist = [ 0, 2, 4, 6, 8, 10, 12, 14, 16 ]
del(Mylist[4])
print(Mylist)
del(Mylist[:4])
print(Mylist)
del(Mylist[2:])
print(Mylist)
[0, 2, 4, 6, 10, 12, 14, 16]
[10, 12, 14, 16]
[10, 12]
11) Mylist = [ 0, 2, 4, 6, 8, 8, 10, 12, 14 ]
Mylist.remove(8)
print(Mylist)
Mylist.pop(2)
print(Mylist)
[0, 2, 4, 6, 8, 10, 12, 14]
[0, 2, 6, 8, 10, 12, 14]
12) Mylist = [ 0, 2, 4, 6, 8, 8, 10, 12, 14 ]
Mylist.remove(8)
print(Mylist)
[0, 2, 4, 6, 8, 10, 12, 14]
13) Mylist = [ 0, 2, 4, 6, 8, 8, 10, 12, 14 ]
Mylist.pop(2)
Mylist.insert(2,4)
Mylist.remove(6)
Mylist.pop(3)
print(Mylist)
[0, 2, 4, 8, 10, 12, 14]
14) Mylist = [ 0, 2, 4, 6, 8, 8, 10, 12, 14 ]
del Mylist
print(Mylist)
Error ('Mylist' is not defined)
15) Mylist = [ 0, 2, 4, 6, 8, 8, 10, 12, 14 ]
Mylist.clear()
print(Mylist)
print("Number of elements in the list is",len(Mylist))
[]
Number of elements in the list is 0
..3..
16) l1 = list(range(2,11,2))
print(l1)
l2 = list(range(11))
print(l2)
l3 = list(range(-9,0,2))
print(l3)
[2, 4, 6, 8, 10]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[-9, -7, -5, -3, -1]
17) squares = []
for x in range(1,11):
s = x ** 2
squares.append(s)
print (squares)
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
18) cubes = [ x ** 3 for x in range(1,5) ]
print (cubes)
[1, 8, 27, 64]
19) Mymarks = [72,69,80,77,80,90]
print(Mymarks[0])
print(Mymarks.count(80))
print(Mymarks.index(80))
Mymarks.reverse()
print(Mymarks)
Mymarks.sort()
print(Mymarks)
72
2
2
[90, 80, 77, 80, 69, 72]
[69, 72, 77, 80, 80, 90]
20) Mymarks = [72,69,80,77,80,90]
print("1. ", Mymarks[5])
print("2. ", max(Mymarks))
print("3. ", min(Mymarks))
print("4. ", Mymarks)
print("5. ", sum(Mymarks))
print("1 - is my computer mark\n2 - is my highest mark\n
3 - is lowest mark and\n4 - is my marks of first revision
\n5 - is my total mark")
..4..
1. 90
2. 90
3. 69
4. [72, 69, 80, 77, 80, 90]
5. 468
1 - is my computer mark
2 - is my highest mark
3 - is lowest mark and
4 - is my marks of first revision
5 - is my total mark
21) divBy4=[ ]
for i in range(21):
if (i%4==0):
divBy4.append(i)
print(divBy4)
[0, 4, 8, 12, 16, 20]
22) Can you guess what are a, b and c in the following snippet? / பின்வரும்
குைியீட்டில் a, b மற்றும் c ஆகியன என்ன என்று உங்களால் யூகிக்க முடிகிைதா?
a=[4]
b=(4)
c=(4,)
Yes./ஆம்.
a → List
b → Variable
c → Tuple
23) a=[4]
b=(4)
c=(4,)
print("The value of a is",a,"and its type is",type(a))
print("The value of b is",b,"and its type is",type(b))
print("The value of c is",c,"and its type is",type(c))
The value of a is [4] and its type is <class 'list'>
The value of b is 4 and its type is <class 'int'>
The value of c is (4,) and its type is <class 'tuple'>
24) Mymarks = (72,69,80,77,80,90)
print("My language marks are",Mymarks[:2])
print("My subject marks are",Mymarks[2:])
print("My top mark is",max(Mymarks))
..5..
My language marks are (72, 69)
My subject marks are (80, 77, 80, 90)
My top mark is 90
25) num=[10,20,30,40,50]
num[2]=35
print(num)
[10, 20, 35, 40, 50]
26) num=(10,20,30,40,50)
num[2]=35
print(num)
Error! (Tuple is immutable)
27) (a, b, c) = (34, 90, 76)
print(a,b,c)
(x, y, z) = (a*2, b/3, c+4)
print(x,y,z)
(p, q, r,s) = (2*2, 2**2, 3*2, 3**3)
print(p, q, r,s)
34 90 76
68 30.0 80
4 4 6 27
28) Toppers = (("Vinodini", "XII-F", 98.7), ("Soundarya", "XII-H", 97.5),
("Tharani", "XII-F", 95.3), ("Saisri", "XII-G", 93.8))
print(Toppers[0])
print(Toppers[1][0])
print(Toppers[2])
print(Toppers[0][0], Toppers[1][1], Toppers[2][2])
print("Check the difference of the following outputs:")
print(Toppers)
for i in Toppers:
print(i)