0% found this document useful (0 votes)
3 views7 pages

Python List Operations and Outputs

The document contains a series of programming exercises and outputs related to Python lists, tuples, and dictionaries. It includes tasks such as counting elements, modifying lists, and understanding data types, along with their expected outputs. The exercises are aimed at enhancing students' understanding of basic data structures in Python.

Uploaded by

gsharan2005
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Python List Operations and Outputs

The document contains a series of programming exercises and outputs related to Python lists, tuples, and dictionaries. It includes tasks such as counting elements, modifying lists, and understanding data types, along with their expected outputs. The exercises are aimed at enhancing students' understanding of basic data structures in Python.

Uploaded by

gsharan2005
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

12 – COMPUTER SCIENCE

LESSON – 9

என்றும் மாணவர்கள் நலனில்


ANSWERS / விடைகள்
WRITE THE OUTPUT OF THE FOLLOWING SNIPPETS. / பின்வரும் குறிமுறைகளின் வெளியீட்டை எழுதுக.
1) Write the number of elements in the following list:/ பின்வரும் பட்டியலில் உள்ள
உறுப்புகளின் எண்ணிக்கககய எழுதவும்:

Mylist = [ “Welcome”, 3.14, 10, [2, 4, 6] ]


4
2) Mylist = [ “Welcome”, 3.14, 10, [2, 4, 6] ]
print(Mylist)
print(Mylist[0])
print(Mylist[1])
print(Mylist[-2])
print(Mylist[-1])
print(Mylist[-1][1])
['Welcome', 3.14, 10, [2, 4, 6]]
Welcome
3.14
10
[2, 4, 6]
4
3) Mylist1 = [ "Welcome", 3.14, 10, [2, 4, 6] ]
Mylist2 = [ "Welcome", 3.14, 10, 2, 4, 6 ]
print("Number of elements in list1 is",len(Mylist1))
print("Number of elements in list2 is",len(Mylist2))
Number of elements in list1 is 4
Number of elements in list2 is 6
4) Mylist = [ 2, 4, 6 ]
[Link](8)
[Link]([10, 14])
[Link](5,12)
print(Mylist)
[2, 4, 6, 8, 10, 12, 14]

..1.. A. PRABHAKAR - 9442979144


5) Find the correct statement to add multiple elements to the list “Mylist=[2,4,6]”
/ "Mylist=[2,4,6]" என்ற List-ல் பல உறுப்புககளச் சேர்க்க பயன்படும் ேரியான

கூற்கைக் கண்டைியவும்.

(a) [Link](8, 10)


(b) [Link]([8,10])
(b) is the correct statement./ (b) சரியான கூற்று
6) Mylist = [ 2, 4, 6 ]
[Link](0,0)
[Link]([8])
[Link](14)
[Link](5,12)
print(Mylist)
[0, 2, 4, 6, 8, 12, 14]

7) Mylist = [ 2, 4, 6 ]
[Link](0,0)
[Link]([8])
[Link](14)
[Link](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.. A. PRABHAKAR - 9442979144


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 ]
[Link](8)
print(Mylist)
[Link](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 ]
[Link](8)
print(Mylist)
[0, 2, 4, 6, 8, 10, 12, 14]
13) Mylist = [ 0, 2, 4, 6, 8, 8, 10, 12, 14 ]
[Link](2)
[Link](2,4)
[Link](6)
[Link](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 ]
[Link]()
print(Mylist)
print("Number of elements in the list is",len(Mylist))
[]
Number of elements in the list is 0

..3.. A. PRABHAKAR - 9442979144


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
[Link](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([Link](80))
print([Link](80))
[Link]()
print(Mymarks)
[Link]()
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.. A. PRABHAKAR - 9442979144


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):
[Link](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.. A. PRABHAKAR - 9442979144


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)

('Vinodini', 'XII-F', 98.7)


Soundarya
('Tharani', 'XII-F', 95.3)
Vinodini XII-H 95.3
Check the difference of the following outputs:
(('Vinodini', 'XII-F', 98.7), ('Soundarya', 'XII-H', 97.5), ('Tharani', 'XII-F', 95.3), ('Saisri', 'XII-G',
93.8))
('Vinodini', 'XII-F', 98.7)
('Soundarya', 'XII-H', 97.5)
('Tharani', 'XII-F', 95.3)
('Saisri', 'XII-G', 93.8)
..6.. A. PRABHAKAR - 9442979144
29) setA = {3,6,9}
setB = {1,3,9}
print("1. Union :",setA|setB)
print("2. Intersection :", [Link](setB))
print("3. Difference :",[Link](setB))
print("4. Symmetric difference :", setA^setB)
1. Union : {1, 3, 6, 9}
2. Intersection : {9, 3}
3. Difference : {6}
4. Symmetric difference : {1, 6}
30) Match / பபாருத்துக.
1. Union : (a) – (minus)
2. Intersection : (b) | (pipeline)
3. Difference : (c) ^ (caret)
4. Symmetric difference: (d) & (ampersand)
1. – (b), 2. (d), 3. – (a), 4. – (c)
31) Dict_Stud = { 'RollNo': '1234', 'Name':'Murali', 'Class':'XII',
'Marks':'451'}
print(Dict_Stud)
print("My name and marks are")
print(Dict_Stud['Name'])
print(Dict_Stud['Marks'])
{'RollNo': '1234', 'Name': 'Murali', 'Class': 'XII', 'Marks': '451'}
My name and marks are
Murali
451
32) Dict1 = { x : 2 * x for x in range(1,5)}
print(Dict1)
Dict2 = { x : x ** 2 for x in range(1,5)}
print(Dict2)
Dict3 = { x : x ** 3 for x in range(1,5)}
print(Dict3)
{1: 2, 2: 4, 3: 6, 4: 8}
{1: 1, 2: 4, 3: 9, 4: 16}
{1: 1, 2: 8, 3: 27, 4: 64}
33) a=[x**2 for x in range(5)]
b=tuple(a)
c={x**2 for x in range(5)}
print(a)
print(b)
print(c)
[0, 1, 4, 9, 16]
(0, 1, 4, 9, 16)
{0, 1, 4, 9, 16}
..7.. A. PRABHAKAR - 9442979144

You might also like