Practice
Practice
Q1. A binary file “Book.dat” has structure [BookNo, Book_Name, Author, Price]. 7
a) Write a user defined function CreateFile() to input data for a record and add
to Book.dat .
Q2. Write a python code to add student using mysql connectivity and display the 5
detail of the students whose age is less than 18.
Create database and table as below:
Name of database =school
Name of table = student (roll,name,age,class,city) give primary key and not
null constraints.
Q3. Practical File 7
Q4. Project File 8
Q5. Viva-Voce 3
def countrec(Author):
fobj=open("Book.dat", "rb")
num = 0
try:
while True:
rec=pickle.load(fobj)
if Author==rec[2]:
num = num + 1
print(rec[0],rec[1],rec[2],rec[3])
except:
fobj.close()
return num
createfile()
name=input("please enter the name of author to be searched")
n=countrec(name)
print("Total records", n)
Ans2.
import mysql.connector
mydb = mysql.connector.connect(host=”localhost”, user=”root”,passwd=”admin″)
mycursor = mydb.cursor()
mycursor.execute(“create database school”)
mycursor.execute(“use school”)
mycursor.execute(“create table student (roll int(4) not null primary key, name char(20), age int(3), class
char(4), city char(20)”)
L=[]
roll=int(input("Enter the roll numb er : "))
L.append(roll)
name=input("Enter the Name: ")
L.append(name)
age=int(input("Enter Age of Student : "))
L.append(age)
class=input("Enter the Class : ")
L.append(class)
city=input("Enter the City ofthe Student : ")
L.append(city)
stud=(L)
sql="insert into student (roll,name,age,class,city) values (%s,%s,%s,%s,%s)"
mycursor.execute(sql,stud)
SET – 2
AISSCE Practical Examination 2020 – 2021
def countrec():
fobj=open("student.dat","rb")
num = 0
try:
while True:
rec=pickle.load(fobj)
if rec[2]>75:
num = num + 1
print(rec[0],rec[1],rec[2])
except:
fobj.close()
return num
createfile()
n=countrec()
print(" total no of students achieved percentage more than 75: ", n)
Ans 2
import mysql.connector
mydb = mysql.connector.connect(host=”localhost”, user=”root”,passwd=”admin″)
mycursor = mydb.cursor()
mycursor.execute(“create database library”)
mycursor.execute(“use library”)
mycursor.execute(“create table book (bno int(4) not null primary key, bname char(20), author
char(20),price int(3)”)
L=[]
bno=int(input("Enter the Book number : "))
L.append(bno)
bname=input("Enter the Book Name: ")
L.append(bname)
author=input("Enter the author : ")
L.append(author)
price=int(input("Enter Age of Student : "))
L.append(price)
stud=(L)
sql="insert into book (bno, bname, author, price) values (%s,%s,%s,%s)"
mycursor.execute(sql,stud)
mycursor.execute(“Select * from book where price>1000;”)
mydata=mycursor.fetchall()
for i in mydata:
print(i)
SET – 3
Q1. Write a menu driven program to push book no in stack and pop it from stack . 7
Q2. Write a python code to add product using mysql connectivity and display the 5
detail of the book whose price is in the range of 10 to 20.
Create database and table as below:
Name of database =shop
Name of table = product (pno, pname, price) give primary key and not null
constraints.
Q3. Practical File 7
Q4. Project File 8
Q5. Viva-Voce 3
ANS 1)
stk=[]
cho='Y'
while(cho=='Y' or cho=='y'):
print("Enter 1 : Push")
print("Enter 2 : Pop")
opt=int(input('enter ur choice:='))
if opt==1:
ch='y'
while(ch=='Y' or ch=='y'):
d=int(input("enter book no : "))
stk.append(d)
ch=input('want to add more element y / n?')
elif opt==2:
if (stk==[]):
print( "Stack empty")
else:
p=stk.pop()
print ("Deleted element:", p)
print"----------------------------"
for i in stk:
print(i)
else:
print('invalid choice')
cho=input('want to continue stack operation y / n?')
Ans 2
import mysql.connector
mydb = mysql.connector.connect(host=”localhost”, user=”root”, passwd=”admin″)
mycursor = mydb.cursor()
mycursor.execute(“create database shop”)
mycursor.execute(“use shop”)
mycursor.execute(“create table product (pno int(4) not null primary key, pname char(20), price int(3)”)
L=[]
pno=int(input("Enter the product number : "))
L.append(pno)
pname=input("Enter the product Name: ")
L.append(pname)
price=int(input("Enter Age of Student : "))
L.append(price)
stud=(L)
sql="insert into product (pno,pname,price) values (%s,%s,%s)"
mycursor.execute(sql,stud)
mycursor.execute(“Select * from product where price>10 and price <=20;”)
mydata=mycursor.fetchall()
for i in mydata:
print(i)