practicals for cs
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, BookName,
Author, Price]. |
7 |
Q2. |
Write
a program in python to display all the records of table “student” already
created in MySQL. |
5 |
Q3. |
Practical
File |
7 |
Q4. |
Project
File |
8 |
Q5. |
Viva-Voce |
3 |
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()
createfile() #
This function is called just to verify result and not required in exam
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
n=countrec(“amit”) #
This function is called just to verify result and not required in exam
print(“Total
records”, n) #
This statement is just to verify result and not required in exam
Ans2.
import
mysql.connector
mydb
= mysql.connector.connect(host=”localhost”,
user=”root”,passwd=”Agnel@123″, database=”amit”)
mycursor
= mydb.cursor()
mycursor.execute(“Select
* from student;”)
for
i in mycursor:
print(i)
SET
– 2
AISSCE
Practical Examination 2020 – 2021
COMPUTER
SCIENCE – 083
Q1. |
A
binary file “student.dat” has structure [admission_number, Name, percentage].
Write a program |
7 |
Q2. |
Write
a program in python to add new column “contactno” of data type Varchar
(length = 10) in |
5 |
Q3. |
Practical File |
7 |
Q4. |
Project File |
8 |
Q5. |
Viva-Voce |
3 |
SOLUTION
OF PRACTICAL QUESTION PAPER SET – 2:
Ans 1
import pickle
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
Ans 2-
import mysql.connector
mydb = mysql.connector.connect(host = “localhost”, user = “root”, passwd = “Agnel@123”, database = “amit”)
mycursor = mydb.cursor( )
mycursor.execute(“alter table student add contactno varchar(10);”)
Comments
Post a Comment