ANIRUTH SRINIVASAN Board Praticals CS
ANIRUTH SRINIVASAN Board Praticals CS
AISSCE PRACTICAL,2022-2023
COMPUTER SCIENCE
N=[12,13,34,56,21,79,98,22,35,38]
stk=[]
def push():
for i in N:
if i>33:
stk.append(i)
def pop():
if stk==[]:
print("Stack Empty!Underflow!")
else:
print(‘Popped out item:’,stk.pop())
def display():
for i in range(len(stk)-1,-1,-1):
print(stk[i],end=",")
push()
pop()
display()
1.(II). Write a Python & MySQL connectivity program to solve the queries.
a. Display students’ records from the table based on gender as female. b.
Display name and age of students whose age is 23 and above. c. Display
details of all the students whose name starts with ‘S’.
TABLE: STUDENT
NO NAME AGE SEX
1 PANKAJ 24 M
2 SHALINI 21 F
3 SANJAY 22 M
4 SUDHA 25 F
5 RAKESH 22 M
#(a)query:
c.execute("select * from STUDENT where SEX='F'")
for i in c:
print(i)
#(b)query:
c.execute("select NAME,AGE from STUDENT where AGE>=22")
for i in c:
print(i)
#(c)query:
c.execute("select * from STUDENT where NAME like 'S%'")
for i in c:
print(i)
def countlines():
file=open("XYZ.txt")
count=0
lines=file.readlines()
for i in lines:
if i[0]=='A' or i[0]=='E':
count+=1
print("Number of lines starting with A or E
are",count)
file.close()
countlines()
2.(II). Write a Python & MySQL connectivity program to solve the queries.
a. To search records from the following STUDENT table based on non medical
students of class 12.
b. List the details of those students who are in class 12 sorted by
name.
c. To list name of female students who are in commerce stream.
TABLE: STUDENT
Rollno Name Stream Class Gender
#(a)query:
c.execute("select * from STUDENT where Stream='Nonmedical' and Class
like '12%'")
for i in c:
print(i)
#(b)query:
c.execute("select * from STUDENT where Class like '12%' order by
name")
for i in c:
print(i)
#(c)query:
c.execute("select Name from STUDENT where Stream='Commerce' and
Gender='F'")
for i in c:
print(i)
3.(I). Write a python program to get student data (Roll number, Name,
mark) from the user and store those details in a CSV file called
“marks.csv” and also display the file contents.
import csv
def write():
file=open('marks.csv','w')
write=csv.writer(file)
n=int(input('Enter no. of records: '))
for i in range(n):
roll=int(input('Enter Roll No: '))
name=input('Enter Name: ')
marks=float(input('Enter Marks: '))
rec=[roll,name,marks]
write.writerow(rec)
file.close()
def read():
file=open('marks.csv','r',newline='\r\n')
read=csv.reader(file)
for i in read:
print(i)
file.close()
write()
read()
a. List the name of students who are in class 12 sorted by average marks.
b. Search minimum of average mark from the above table where average
marks<75.
c. Search following STUDENT table to delete all the records whose Avgmark is
less than 80.
TABLE: STUDENT
Name AvgMark Grade Class
#(a)query:
c.execute("select Name from STUDENT where Class like '12%' order by
AvgMark")
for i in c:
print(i)
#(b)query:
c.execute("select min(AvgMark) from STUDENT where AvgMark<75
")
for i in c:
print(i)
#(c)query:
c.execute("delete from STUDENT where AvgMark<80")
mycon.commit()
c.execute("select * from STUDENT")
for i in c:
print(i)
import pickle
def CreateEmp():
file=open('emp.dat','wb')
n=int(input('Enter no. of records: '))
for i in range(n):
eid=input('Enter E.Id: ')
ename=input('Enter Name: ')
designation=input('Enter Designation: ')
salary=int(input('Enter Salary: '))
l=[eid,ename,designation,salary]
pickle.dump(l,file)
file.close()
def display():
file=open("emp.dat","rb")
try:
while True:
rec=pickle.load(file)
if rec[3]>50000:
print(rec[0],rec[1],rec[2],rec[3])
except:
file.close()
CreateEmp()
display()
#(a)query:
c.execute("update BOOKS set PRICE=PRICE+50 where
PUBLISHERS='EPB'") mycon.commit()
c.execute("select * from BOOKS")
for i in c:
print(i)
#(b)query:
c.execute("select BOOK_NAME from BOOKS order by BOOK_NAME
desc")
for i in c:
print(i)
#(c)query:
c.execute("select * from BOOKS where PRICE>400 order by
PUBLISHERS")
for i in c:
print(i)
5.(I). Vikram has a list containing 10 integers. You need to help him create
a program with separate user defined functions to perform the following
operations based on this list.
a. Traverse the content of the list and push the ODD numbers into a
stack.
b. Pop and display the content of the stack.
For Example: N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
The sample output should be 79,21,13
N=[12,13,34,56,21,79,98,22,35,38]
stk=[]
def push():
for i in N:
if i %2!=0:
stk.append(i)
def pop():
if stk==[]:
print("Stack Empty!Underflow!")
else:
print('Popped out item:',stk.pop())
def display():
for i in range(len(stk)- 1,-1,-1):
print(stk[i],end=",")
push()
pop()
display()
#(a)query:
c.execute("select WNO, NAME from WORKER where DOB between '1987-01-01' and
'1991-12-01'")
for i in c:
print(i)
#(b)query:
c.execute("select * from WORKER where NAME like '_____'")
for i in c:
print(i)
#(c)query:
c.execute("select *,SALARY*12 from WORKER where
(SALARY*12)>50000")
for i in c:
print(i)
PREPARED BY:
R.ANIRUTH SREENIVASAN