TECH EASY PROGRAM s for practice
என்றும் மாணவர்கள் நலனில்
12 – கணினி அறிவியல் / COMPUTER SCIENCE
CODING WITH ANSWERS
LESSONS – 5, 6 & 7
WRITE THE OUTPUT OF THE FOLLOWING SNIPPETS. / பின்வரும் குறிமுறைகளின் வெளியீட்டை எழுதுக.
1) >>> 2 5
32
2) >>>100//3
33
3) print(10/3)
print(10//3)
3.3333333333333335
3
4) a,b=10,3
x1=a if (a/b==3) else b
print(x)
x2=a if (a//b==3) else b
print(x)
3
10
5) Match the following: / ப ொருத்துக.
a) 0b1010 - i) Octal Literals
b) 100 - ii) Hexadecimal Literal
c) 0o310 - iii) Binary Literal
d) 0x12c - iv) Decimal Literal
Answer: a) – iii), b) – iv), c) – i) d) – ii)
6) >>> print("\"Python\"")
"Python"
7) a = -5
x="even" if a%2==0 else "odd"
print (a, " is ",x)
-5 is odd
TECH EASY ..1.. A. PRABHAKAR - 9442979144
8) i=10
while (i<=15):
print (i,end='\t')
i=i+1
10 11 12 13 14 15
9) i=10
while (i<=15):
i=i+1
print (i,end='\t')
11 12 13 14 15 16
10) for x in (1,2,3,4,5):
print("Tech Easy")
Tech Easy
Tech Easy
Tech Easy
Tech Easy
Tech Easy
11) for x in (1,2,3,4,5):
print(x, end=' ')
12345
12) n = 10
sum = 0
for counter in range(1, n+1):
sum = sum + counter
print("Sum of 1 until %d: %d" % (n, sum))
Sum of 1 until 10: 55
13) for x in range(5):
if x==2:
continue
print(x, end='')
0134
14) for i in range(1,10,2):
print(i, end='')
13579
TECH EASY ..2.. A. PRABHAKAR - 9442979144
15) i=1
while (i<=6):
for j in range (1,i):
print (j,end='\t')
print (end='\n')
i += 1
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
16) i=1
while (i<=6):
for j in range (1,i):
print (‘$’,end='\t')
print (end='\n')
i += 1
$
$ $
$ $ $
$ $ $ $
$ $ $ $ $
17) i=1
while True:
if i%5 == 0:
break
print(i,end=' ')
i +=1
1234
18) for cs in “tech easy”:
if cs=='e':
pass
print(cs, end='')
tech easy
TECH EASY ..3.. A. PRABHAKAR - 9442979144
19) for sub in “computer science”:
if sub=="e":
continue
print(sub, end='')
computr scinc
20) def hello():
print ("hello - Python")
return
print (hello())
hello - Python
None
21) def printinfo(name, salary = 3500):
print ("Name: ", name)
print ("Salary: ", salary)
return
printinfo("Mani")
Name: Mani
Salary: 3500
22) def printnos (*nos):
for n in nos:
print(n)
return
printnos (1,2,10,30,7)
1
2
10
30
7
23) c = 1
def add():
c = c + 2
print(c)
add()
ERROR!
TECH EASY ..4.. A. PRABHAKAR - 9442979144
24) c = 1
def add():
global c
c = c + 2
print (c)
add()
3
25) x = 0
def add():
global x
x = x + 5
print ("Inside add() function x value is :", x)
add()
print ("In main x value is :", x)
Inside add() function x value is : 5
In main x value is : 5
26) print ('A = ',ord(‘A’))
print(chr(97))
print (type(15.2))
A = 65
a
<class 'float'>
27) MyList = [-21,-76,-98,-23]
print ('Maximum of MyList :', max(MyList))
Maximum of MyList : -21
28) n1=17.89
print (round (n1))
print (round (n1,0))
print (round (n1,1))
print (round (n1,2))
18
18.0
17.9
17.89
29) x=26.7
print([Link](x))
print([Link](x))
26
27
TECH EASY ..5.. A. PRABHAKAR - 9442979144
30) print(format(66, 'c'))
print(format(10, 'x'))
print(format(10, 'X'))
print(format(0b110, 'd'))
print(format(0xa, 'd'))
B
a
A
6
10
31) print(pow(3,2))
print(pow(-3,2))
print(pow(-3,3))
9
9
-27
32) print(abs(-8))
print(abs(8))
8
8
import math
print(eval('25*2-5*4')) 30
print([Link](abs(-81))) 9.0
print([Link](3.5+4.6)) 9
print([Link](3.5+4.6)) 8
print(abs(-25+12.0)) 13.0
print(abs(-3.2)) 3.2
print(ord('2')) 50
print(ord('$')) 36
print(type('s')) <class 'str'>
print(bin(16)) 0b10000
print(round(18.2,1)) 18.2
print(round(18.2,0)) 18.0
print(round(0.5100,3)) 0.51
print(round(0.5120,3)) 0.512
print(format(66, 'c')) B
print(format(10, 'x')) a
print(format(10, 'X')) A
print(format(0b110, 'd')) 6
print(format(0xa, 'd')) 10
TECH EASY ..6.. A. PRABHAKAR - 9442979144
print(pow(2,-3)) 0.125
print(pow(2,3.0)) 8.0
print(pow(2,0)) 1
print(pow((1+2),2)) 9
print(pow(-3,2)) 9
print(pow(2*2,2)) 16
LESSON – 8
WRITE THE OUTPUT OF THE FOLLOWING SNIPPETS. / பின்வரும் குறிமுறைகளின் வெளியீட்டை எழுதுக.
1) >>> print (‘I am the best student’)
I am the best student
2) >>> print ('Greater Chennai Corporation's student')
ERROR! (SyntaxError: invalid syntax )
3) str1 = "Chennai Schools"
str1[7] = "-"
ERROR! (Type error)
4) str1 = "Chennai Schools"
str1= "Delhi Schools"
print(str1)
Delhi Schools
5) s="How are you?"
print([Link]("o","e"))
Hew are yeu?
6) s="How are you?"
[Link]("o","e")
print(s)
How are you?
7) str1=" Welcome to "
str1+="Learn Python"
print (str1*3)
Welcome to Learn Python Welcome to Learn Python Welcome to Learn Python
8) str1 = "Welcome to Government School"
print (str1[11:21])
print (str1[11:21:4])
print (str1[11:21:3])
print (str1[11:21:2])
print (str1[::3])
print (str1[::-3])
TECH EASY ..7.. A. PRABHAKAR - 9442979144
Government
Grn
Gemt
Gvrmn
Wceoore hl
lh erooecW
9) str1="TamilNadu"
print(str1[::-1]
udaNlimaT
10) str1="THIRUKKURAL"
print (str1[5])
print (str1[:5])
print (str1[5:])
K
THIRU
KKURAL
11) str1="COMPUTER"
index=0
for i in str1:
print (str1[:index+1])
index+=1
C
CO
COM
COMP
COMPU
COMPUT
COMPUTE
COMPUTER
12) str1="COMPUTER"
index=len(str1)
for i in str1:
print (str1[:index])
index-=1
COMPUTER
COMPUTE
COMPUT
COMPU
COMP
COM
CO
C
TECH EASY ..8.. A. PRABHAKAR - 9442979144
13) city="chennai"
print([Link]())
print(city)
print([Link]().swapcase())
Chennai
chennai
cHENNAI
14) str1="tech easy"
str2="Tech"
if str2 in str1:
print ("Found")
else:
print ("Not Found")
str4="tech"
if str4 in str1:
print ("Found")
else:
print ("Not Found")
Not Found
Found
15) str1=' * '
i=5
while i>=1:
print (str1*i)
i-=1
* * * * *
* * * *
* * *
* *
*
16) str1="ABCDEFGH"
str2="ate"
for i in str1:
print ((i+str2),end='\t')
Aate Bate Cate Date Eate Fate Gate Hate
17) str1 = "welcome"
str2 = "to school"
str3=str1[:2]+str2[len(str2)-2:]
print(str3)
weol
TECH EASY ..9.. A. PRABHAKAR - 9442979144
18) str1 = "welcome"
str2 = "to school"
str3=str1[3:]+str2[:len(str2)]
print(str3)
cometo school
19) str1='education department'
print([Link]())
print([Link]())
print([Link]())
print(str1)
Education department
Education Department
EDUCATION DEPARTMENT
education department
20) str1="Welcome "
str1 + " by Tech Easy"
print(str1)
str1 += " by Tech Easy"
print(str1)
Welcome
Welcome by Tech Easy
21) str1="Tech Easy"
The positive index of the character ‘h’ is 3
The negative index of the character ‘h’ is -6
LESSON – 9
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])
TECH EASY ..10.. A. PRABHAKAR - 9442979144
['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]
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])
TECH EASY ..11.. A. PRABHAKAR - 9442979144
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]
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]
TECH EASY ..12.. A. PRABHAKAR - 9442979144
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
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) Mymarks = [72,69,80,77,80,90]
print(Mymarks[0])
print([Link](80))
print([Link](80))
[Link]()
print(Mymarks)
[Link]()
print(Mymarks)
TECH EASY ..13.. A. PRABHAKAR - 9442979144
72
2
2
[90, 80, 77, 80, 69, 72]
[69, 72, 77, 80, 80, 90]
19) cubes = [ x ** 3 for x in range(1,5) ]
print (cubes)
[1, 8, 27, 64]
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")
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
TECH EASY ..14.. A. PRABHAKAR - 9442979144
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))
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])
TECH EASY ..15.. A. PRABHAKAR - 9442979144
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)
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
TECH EASY ..16.. A. PRABHAKAR - 9442979144
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}
LESSON – 10, 12 & 13
1) class Student:
mark1, mark2, mark3 = 45, 91, 71
def process(self):
sum = Student.mark1 + Student.mark2 + Student.mark3
avg = sum/3 print("Total Marks = ", sum)
print("Average Marks = ", avg)
return
Anil=Student()
[Link]()
(a) Name of the class / இனக்குழுவின் பெயர்
Student
(b) Name of the method / வழிமுறையின் பெயர்
process
(c) Write the class instantiation statement. /
சான்றுருவாக்கல் (பெொருள் உருவொக்கும்) கூற்றை எழுதுக.
Anil=Student()
(d) Which member accessed using the object? Write that statement. /
பபாருளைப் பயன்படுத்தி எந்த உறுப்றெ அணுகியுள்ள ொம்? அந்த கூற்றை எழுதுக.
process member
[Link]()
(e) Name of the object / இனக்குழுவின் பெயர்
Anil
TECH EASY ..17.. A. PRABHAKAR - 9442979144
(f) Write the output of the program. / நிரலின் பவளியீட்றை எழுதுக.
Total Marks = 207
Average Marks = 69.0
2) The correct syntax of class instantiation is /
இனக்குழு பெொருள் (சான்றுருவாக்கல்) உருவொக்களின் ப ொைரியல்
(a) Object_name = class_name( ) (b) class_name = Object_name ( )
(c) class_name Object_name ( ) (d) class_name Object_name:
(a) Object_name = class_name( )
3) The correct syntax for accessing class member is /
இனக்குழு உறுப்றெ அணுகுவதற்கான சரியான ப ொைரியல்
(a) class_member.Object_name (a) Object_name=class_member
(c) Object_name.class_member (a) Object_name.class_member()
(c) Object_name.class_member
4) The class method must have the first parameter named as _______ / இனக்குழு வழிமுளையின்
முதல் அைபுரு கண்டிப்பாக ____ என இருக்க வவண்டும்.
self
5) Write the output of the program. / நிரலின் வெளியீட்டை எழுதுக.
class Odd_Even:
def check(self, num):
if num%2==0:
print(num," is Even number")
else:
print(num," is Odd number")
n=Odd_Even()
[Link](5)
5 is Odd number
6) class Sample:
def __init__(self, num):
print("Constructor of class Sample...")
self.a=num
print("The value of instance variable is :", self.a)
S1=Sample(10)
S2=Sample(15)
print("Instance variables value varies from object to object.")
(a) Name the parameter that passed to the constructor /
ஆக்கிக்கு அனுப்பப்பட்ட அைபுருவின் பபயளைக் குறிப்பிடவும்
num
(b) Name the instance variable / சான்றுரு மாறியின் பெயர்
a
TECH EASY ..18.. A. PRABHAKAR - 9442979144
(c) Write the output of the program. / நிரலின் பவளியீட்றை எழுதுக.
Constructor of class Sample...
The value of instance variable is : 10
Constructor of class Sample...
The value of instance variable is : 15
Instance variables value varies from object to object.
7) Write the output of the program. / நிரலின் வெளியீட்டை எழுதுக.
class Sample:
n1 = 12
__n2 = 14
_n3=16
def display(self):
print("Class variable 1 = ", self.n1)
print("Class variable 2 = ", self.__n2)
print("Class variable 3 = ", self._n3)
S=Sample()
[Link]()
Class variable 1 = 12
Class variable 2 = 14
Class variable 3 = 16
8) Write the output of the program. / நிரலின் வெளியீட்டை எழுதுக.
class Sample:
n1 = 12
__n2 = 14
_n3=16
def display(self):
print("Class variable 1 = ", self.n1)
print("Class variable 2 = ", self.__n2)
print("Class variable 3 = ", self._n3)
S=Sample()
[Link]()
print("Value 1 = ", S.n1)
print("Value 2 = ", S.__n2)
print("Value 2 = ", S._n3)
Class variable 1 = 12
Class variable 2 = 14
Class variable 3 = 16
Value 1 = 12
ERROR!
TECH EASY ..19.. A. PRABHAKAR - 9442979144
Why it shows error? / அது ஏன் பிழைழைக் காட்டுகிறது?
The class variables n2 and n3 are not accessed because both are under private and protected respectively.
இனக்குழு மாறிகைான n2 மற்றும் n3 அணுக இயலாது. ஏபனனில், ஏபனனில் இைண்டும் முளைவய private மற்றும்
protectedன் கீழ் உள்ைன.
9) Write the output of the program. / நிரலின் வெளியீட்டை எழுதுக.
class Sample:
num=0
def __init__(self, var):
[Link]+=1
[Link]=var
print("The object value is = ", var)
print("The count of object created = ", [Link])
S1=Sample(15)
S2=Sample(35)
S3=Sample(45)
The object value is = 15
The count of object created = 1
The object value is = 35
The count of object created = 2
The object value is = 45
The count of object created = 3
10) Write the output of the program. / நிரலின் வெளியீட்டை எழுதுக.
class String:
def __init__(self):
[Link]=0
[Link]=0
[Link]=0
[Link]=0
[Link]=0
[Link]=""
def getstr(self,a):
[Link]=a
def count (self):
for ch in [Link]:
if ([Link]()):
[Link]+=1
if ([Link]()):
[Link]+=1
TECH EASY ..20.. A. PRABHAKAR - 9442979144
if (ch in ('AEIOUaeiou')):
[Link]+=1
if ([Link]()):
[Link]+=1
[Link] = [Link]+[Link] - [Link]
def display(self):
print("The given string \"",[Link],"\" contains...")
print("%d Uppercase letters"%[Link])
print("%d Lowercase letters"%[Link])
print("%d Vowels"%[Link])
print("%d Consonants"%[Link])
print("%d Spaces"%[Link])
S = String()
[Link]("Tech Easy")
[Link]()
[Link]()
The given string “Tech Easy” contains...
2 Uppercase letters
6 Lowercase letters
3 Vowels
3 Consonants
1 Spaces
11) Write the output of the program. / நிரலின் வெளியீட்டை எழுதுக.
class Student:
def __init__(self, name):
[Link]=name
print ([Link])
S=Student(“Tamil”)
Tamil
TECH EASY ..21.. A. PRABHAKAR - 9442979144
12) Based on the following table answer the given questions below: / பின்வரும்
அட்டவழையின் அடிப்பழடயில் கீழை ககாடுக்கப்பட்டுள்ள ழகள்விகளுக்கு பதிலளிக்கவும்:
(a) SELECT Admno, Name FROM Student;
(b) SELECT Admno, Name, Place FROM Student WHERE Place = ῾Chennai᾿;
(c) SELECT Admno, Name, Age, Place FROM Student
WHERE (Age>=18 AND Place = ῾Delhi᾿);
(d) SELECT Admno, Name, Age FROM Student WHERE Age NOT BETWEEN 18 AND 19;
TECH EASY ..22.. A. PRABHAKAR - 9442979144
(e) SELECT Admno, Name, Place FROM Student
WHERE Place IN (῾Chennai᾿, ῾Delhi᾿);
(f) SELECT * FROM Student WHERE Age>=18 ORDER BY Name DESC;
(g) SELECT Gender, count(*) FROM Student GROUP BY Gender;
(h) SELECT Place , count(*) FROM Student
GROUP BY Place HAVING place = ‘Chennai’;
13) What is the output of the following program? /
பின்வரும் நிரலின் வவளியீடு யாது?
if the file called “[Link]” contain the following details /
“[Link]” என்ற ககாப்பில் கீகேயுள்ள விவரங்களளக் வகாண்டிருப்பின்
chennai,mylapore
mumbai,andheri
import csv
d=[Link](open('c:\PYPRG\ch13\[Link]'))
next(d)
for row in d:
print(row)
mumbai,Andheri
TECH EASY ..23.. A. PRABHAKAR - 9442979144
14) What will be written inside the file [Link] using the following program? /
“[Link]” என்ற ககாப்பில் பின்வரும் நிரல் என்ன விவரத்ளை எழுதும்?
import csv
D = [['Exam'],['Quarterly'],['Halfyearly']]
csv.register_dialect('M',lineterminator = '\n')
with open('c:\pyprg\ch13\[Link]', 'w') as f:
wr = [Link](f,dialect='M')
[Link](D)
[Link]()
Exam,
Quarterly,
Halfyearly
LESSON – 14, 15 & 16
1) The syntax for accessing the functions from the module is /
கூறுநிலையில் இருந்து செயற்குழுவை அணுகுவதற்கான சதாடரியல்
(a) <module name> . <function name>
(b) <function name> . <module name>
(c) <module name> . <parameters>
(d) <function name> . <Parameters>
(a) <module name> . <function name>
2) In the following statement the second argument “args” contains ________ if there
is no error in the command line. / கட்டலை வரியில் பிலை இல்லை என்றால் பின்வரும் கூற்றில்
இரண்டாவது அளபுரு “args” எதவைக் சகாண்டிருக்கும்?
opts, args = [Link] (argv, "i:",['ifile='])
[ ] empty / வெருமையாக இருக்கும்
3) Answer the given questions based on the following snippet. / பின்வரும் வினாக்களுக்கு
கீழ்க்காணும் குறிமுவையின் அடிப்பலடயில் விலடயளிக்கவும்.
if __name__ =='__main__':
main([Link][1:])
(a) Identify the function call statement /
செயற்கூறு அலைப்பு கூற்லற அலடயாைம் காணவும்.
main([Link][1:])
(b) The special varaiable __name__ contains _______
__name__ என்ை சிைப்பு மாறி எதலன சகாண்டிருக்கும்?
Python filename
TECH EASY ..24.. A. PRABHAKAR - 9442979144
(c) If the source file is executed as the main program, the interpreter sets
the __name__ variable to have a value ________ / மூைக் ககாப்பு முதன்லை நிரைாக
செயல்படுத்தப்பட்டால், ைரிசைாழி மாற்றி __name__ ைாறிக்கு இருத்தப்படும் மதிப்பு ________
“__main__”.
4) import sqlite3
con = [Link]('[Link]')
cursor = [Link]()
[Link]("SELECT name FROM sqlite_master WHERE type='table';")
(a) Name of the database / தரவுத்தளத்தின் பபயர்
Academy
(b) Name of the database table / தரவுத்தள அட்டைவையின் பபயர்
sqlite_master
(c) [Link](“…”) - statement shows ______ / இக்கூற்று எைற்வை பைளிக்காட்டும்?
It shows the list of tables created in a database “Academy”.
இது "Academy" என்ற தரவுத்தளத்தில் உருவாக்கப்பட்ட அட்டவணைகளின் பட்டியணைக்
காட்டுகிறது.
(d) It is a control structure used to traverse and fetch the records of the
databaseand all the commands will be executed using _______ object. / இது
தரவுத்தைத்தின் பதிவுகலைக் கடந்து செல்ைவும் சபறவும் பயன்படுத்தப்படும் ஒரு கட்டுப்பாட்டு
கட்டலைப்பாகும், கைலும் அலனத்து கட்டலைகளும் _______ சபாருலைப் பயன்படுத்தி
செயல்படுத்தப்படும்.
cursor
5) Read the following details. Based on that write a python script to display
department wise records. / பின்வரும் விவரங்கலை படிக்கவும், அதன் அடிப்பலடயில் துலற
வாரியாக பதிவுகலை திலரயிட லபத்தான் ஸ்கிரிப்லட எழுதவும்.
database name :- [Link]
Table name :- Employee
Columns in the table :- Eno, EmpName, Esal, Dept
Python script:
import sqlite3
connection=[Link]("[Link]")
cursor=[Link]()
[Link]("""create table employee(eno integer primary key, empname
varchar(20), esal integer, dept varchar(20));""")
TECH EASY ..25.. A. PRABHAKAR - 9442979144
[Link]("""insert into employee values ("1001", "Raja", "10500",
"Sales");""")
[Link]("""insert into employee values ("1002", "Surya", "9000",
"Purchase");""")
[Link]("""insert into employee values ("1003", "Peter", "8000",
"Production");""")
[Link]()
print("Employee Details Department-wise :")
[Link]("""Select * from employee order by dept;""")
result=[Link]()
print(*result, sep="\n")
[Link]()
6) Read the following details. Based on that write a python script to display
records in descending order of Eno / பின்வரும் விவரங்கலை படிக்கவும் அதன் அடிப்பலடயில்
பதிவுகலை Eno இறங்கு வரிலெயில் திலரயிட லபத்தான் ஸ்கிரிப்லட எழுதவும்.
database name :- [Link]
Table name :- Employee
Columns in the table :- Eno, EmpName, Esal, Dept
Python script:
import sqlite3
connection=[Link]("[Link]")
cursor=[Link]()
[Link]("""create table employee(eno integer primary key, empname
varchar(20), esal integer, dept varchar(20));""")
[Link]("""insert into employee values ("1001", "Raja", "10500",
"Sales");""")
[Link]("""insert into employee values ("1002", "Surya", "9000",
"Purchase");""")
[Link]("""insert into employee values ("1003", "Peter", "8000",
"Production");""")
[Link]()
print("Records in descending order of employee number:")
[Link]("""Select * from employee order by eno desc""")
result=[Link]()
print(*result,sep="\n")
[Link]()
TECH EASY ..26.. A. PRABHAKAR - 9442979144
7) Write the Python script to display all the records of the following table using
fetchmany(). / fetchmany( ) பயன்படுத்தி பின்வரும் அட்டவலணயிலுள்ை அலனத்து பதிவுகலையும்
திலரயிடுவதற்கான லபத்தான் ஸ்கிரிப்லட எழுதவும்.
Icode Item_Name Rate
1003 Scanner 10500
1004 Speaker 3000
1005 Printer 8000
1008 Monitor 15000
1010 Mouse 700
Python script:
import sqlite3
connection=[Link]("[Link]")
cursor=[Link]()
[Link]("""select * from product;""")
print("Displaying all records in the table")
result=[Link](5)
print(*result, sep="\n")
[Link]()
8) Write a Python script to create a table called ITEM with following specification.
Add one record to the table. / பின்வரும் குறிப்புகலைக் சகாண்டு Item என்ற அட்டவலணலய
உருவாக்க லபத்தான் ஸ்கிரிப்ட்லட எழுதவும். அட்டவலணக்கு ஒரு பதிலவ கெர்க்கவும்.
Name of the database / தரவுத்தளத்தின் கபைர் : ABC
Name of the table / அட்டவழையின் கபைர்: Item
Column name and specification / கெடுவரிழையின் கபைர் மற்றும் விவரங்கள்:
Icode : Integer and act as Primary Key
Item_Name : Character with length 25
Rate : Integer
Record to be added : 1008, Monitor, 15000
Python script:
import sqlite3
connection=[Link]("[Link]")
cursor=[Link]()
[Link]("""drop table item;""")
[Link]("""create table item(icode integer primary key, itemname
varchar(25), rate integer);""")
[Link]("""insert into item values("1005","Printer","8000");""")
[Link]()
[Link]()
print("Item table is created and a record is added Successfully")
TECH EASY ..27.. A. PRABHAKAR - 9442979144
9) Consider the following table Supplier and item. Write a python script for (i)
to (ii) / பின்வரும் Supplier ைற்றும் Item அட்டவலணகலை கவனித்து (i) ைற்றும் (ii) வினாக்களுக்கு
லபத்தான் ஸ்கிரிப்ட்லட எழுதவும்.
SUPPLIER
Suppno Name City Icode SuppQty
S001 Prasad Delhi 1008 100
S002 Anu Bangalore 1010 200
S003 Shahid Bangalore 1008 175
S004 Akila Hydrabad 1005 195
S005 Girish Hydrabad 1003 25
S006 Shylaja Chennai 1008 180
S007 Lavanya Mumbai 1005 325
i) Display Name, City and Itemname of suppliers who do not reside in
Delhi./ சடல்லியில் வசிக்காத சைாத்த விற்பலனயாைர்களின் Name, City ைற்றும் Itemname கலை
திலரயிடவும்.
ii) Increment the SuppQty of Akila by 40 / அகிைாவின் SuppQty யில் உள்ை ைதிப்கபாடு
40-லய அதிகரிக்கவும்.
Python script:
import sqlite3
connection=[Link]("[Link]")
cursor=[Link]()
# i) Display Name, City and Itemname of suppliers who do not reside in Delhi.
# i) டெல்லியில் வசிக்காத ட ாத்த விற்பனையாளர்களின் Name, City ற்றும் Itemname
[Link] ("SELECT [Link], [Link], [Link] FROM
supplier, item WHERE [Link] <> ’Delhi’ ")
ans=[Link] ( )
for i in ans:
print()
# ii) Increment the SuppQty of Akila by 40
# (ii) அகிலாவின் SuppQty யில் உள்ள திப்பபாடு 40-னய அதிகரித்தல்.
[Link] ("UPDATE supplier SET [Link] =S uppQty + 40
WHERE name=’Akila’ ")
[Link]()
[Link]()
TECH EASY ..28.. A. PRABHAKAR - 9442979144
10) Draw the output for the following Python matplotlip codes. / பின்வரும் வபத்தான்
matplotlip குறிமுவைகளுக்காை ைவரபடங்வள ைவரயவும்.
(a) import [Link] as plt
[Link]([1,2,3,4])
[Link]()
(b) import [Link] as plt
[Link]([1,2,3,4], [1,4,9,16])
[Link]()
TECH EASY ..29.. A. PRABHAKAR - 9442979144
(c) import [Link] as plt
x = [1,2,3]
y = [5,7,4]
x2 = [1,2,3]
y2 = [10,14,12]
[Link](x, y, label='Line 1')
[Link](x2, y2, label='Line 2')
[Link]('X-Axis')
[Link]('Y-Axis')
[Link]('LINE GRAPH')
[Link]()
[Link]()
(d) import [Link] as plt
years = [2014, 2015, 2016, 2017, 2018]
total_populations = [8939007, 8954518, 8960387, 8956741, 8943721]
[Link] (years, total_populations)
[Link] ("Year vs Population in India")
[Link] ("Year")
[Link] ("Total Population")
[Link]()
TECH EASY ..30.. A. PRABHAKAR - 9442979144
(e) import [Link] as plt
labels = ["TAMIL", "ENGLISH", "MATHS", "PHYSICS", "CHEMISTRY", "CS"]
usage = [79.8, 67.3, 77.8, 68.4, 70.2, 88.5]
y_positions = range (len(labels))
[Link] (y_positions, usage)
[Link] (y_positions, labels)
[Link] ("RANGE")
[Link] ("MARKS")
[Link]()
(f) import [Link] as plt
sizes = [89, 80, 90, 100, 75]
labels = ["Tamil", "English", "Maths", "Science", "Social"]
[Link] (sizes, labels = labels, autopct = "%.2f ")
[Link]()
TECH EASY ..31.. A. PRABHAKAR - 9442979144
(g) import [Link] as plt
[Link]([1,3,5,7,9],[5,2,7,8,2], label="Example one")
[Link]([2,4,6,8,10],[8,6,2,5,6], label="Example two", color='g')
[Link]()
[Link]('bar number')
[Link]('bar height')
[Link]('Epic Graph\nAnother Line! Whoa')
[Link]()
வாழ்த்துகளுடன்
அ. பிரபாகர்
TECH EASY ..32.. A. PRABHAKAR - 9442979144