0% found this document useful (0 votes)
60 views

Practice

The document contains 3 sets of sample questions for a Computer Science practical examination. Set 1 contains 2 questions - the first asks to create functions to input book data into a binary file and count books by a given author. The second asks to add student details to a MySQL database and display students under 18. Set 2 contains similar questions - the first involves reading a student data file and displaying results over 75%, the second adds books to a database and displays those over 1000 price. Set 3 asks to create a menu-driven stack program and add/remove books, and add products to a database between 10-20 price range.

Uploaded by

akshat1aps
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Practice

The document contains 3 sets of sample questions for a Computer Science practical examination. Set 1 contains 2 questions - the first asks to create functions to input book data into a binary file and count books by a given author. The second asks to add student details to a MySQL database and display students under 18. Set 2 contains similar questions - the first involves reading a student data file and displaying results over 75%, the second adds books to a database and displays those over 1000 price. Set 3 asks to create a menu-driven stack program and add/remove books, and add products to a database between 10-20 price range.

Uploaded by

akshat1aps
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

SET – 1

AISSCE Practical Examination 2020 – 2021


COMPUTER SCIENCE – 083
Time : 3:00hrs M.M. – 30

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 .

b) Write a function CountRec(Author) in Python which accepts the Author


name as parameter and count and return number of books by the given Author
are stored in the binary file “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

Internal Examiner details External Examiner


details:
Examiner No: Examiner No:
Name: Name:
Sign: Sign:
Date: Date:

SOLUTION OF PRACTICAL QUESTION PAPER SET – 1:


Ans 1
import pickle
def createfile():
fobj=open("Book.dat","ab")
BookNo=int(input("Enter Book Number : "))
Book_name=input("Enter book Name :")
Author = input("Enter Author name: ")
Price = int(input("Price of book : "))
rec=[BookNo, Book_name ,Author, Price]
pickle.dump(rec, fobj)
fobj.close()

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)

mycursor.execute(“Select * from student where age <18;”)


mydata=mycursor.fetchall()
for i in mydata:
print(i)

SET – 2
AISSCE Practical Examination 2020 – 2021

COMPUTER SCIENCE – 083


Time : 3:00hrs M.M. – 30

Q1. A binary file “student.dat” has structure [admission_number, Name, 7


percentage]. Write a program countrec( ) in python that would read
contents of file “students.dat” and display the details of those students
whose percentage is above 75. Also display number of students scoring
above 75%.
Q2. Write a python code to add book using mysql connectivity and display the 5
detail of the book whose price is more than1000.
Create database and table as below:
Name of database =library
Name of table = book (bno,bname,author, price) give primary key and not
null constraints.
Q3. Practical File 7
Q4. Project File 8
Q5. Viva-Voce 3

Internal Examiner details External Examiner


details:
Examiner No: Examiner No:
Name: Name:
Sign: Sign:
Date: Date:

SOLUTION OF PRACTICAL QUESTION PAPER SET – 2:


Ans 1
import pickle
def createfile():
ch='y'
while ch=='y' or ch=='Y':
fobj=open("student.dat","ab")
admission_number =int(input("Enter admission number : "))
name=input("Enter Name of student :")
percentage = int(input("Enter Percentage : "))
rec=[admission_number, name, percentage]
pickle.dump(rec, fobj)
ch=input(" do you want to add more records y/n")
fobj.close()

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

AISSCE Practical Examination 2020 – 2021


COMPUTER SCIENCE – 083

Time : 3:00hrs M.M. – 30

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

Internal Examiner details External Examiner details:


Examiner No: Examiner No:
Name: Name:
Sign: Sign:
Date: Date:

SOLUTION OF PRACTICAL QUESTION PAPER SET – 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)

You might also like