0% found this document useful (0 votes)
873 views16 pages

G12-Cs-Practical QP, Ak

The document provides the question paper for the practical exam in Computer Science for Class 12. It includes questions on writing programs to perform operations on binary and text files, interacting with a database by inserting and retrieving records, and generating reports. For example, question 1a asks students to write a menu driven program to add, display, search and exit records from a binary file containing shoe details. Question 1b tests database skills by asking students to fill in code to connect to a database and insert a record.

Uploaded by

Avilipsa pradhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
873 views16 pages

G12-Cs-Practical QP, Ak

The document provides the question paper for the practical exam in Computer Science for Class 12. It includes questions on writing programs to perform operations on binary and text files, interacting with a database by inserting and retrieving records, and generating reports. For example, question 1a asks students to write a menu driven program to add, display, search and exit records from a binary file containing shoe details. Question 1b tests database skills by asking students to fill in code to connect to a database and insert a record.

Uploaded by

Avilipsa pradhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Senior School Certificate Examination -2022- 23

Practical Question Paper


Subject: Computer Science(083) Class 12
Time: 3:00 Hours Max. Marks: 30

SET-1
Q-1 a) Write a menu driven program to perform following operations into a binary file 8
shoes.dat                                                              

1. Add record
2. Display records
3. Search record
4. Exit

The structure of file content is: [s_id, name, brand, type, price]

Aim:
To Write a menu driven program to perform following operations into a binary file shoes.dat

1. Add record
2. Display records
3. Search record
4. Exit

Program:

import pickle
while True:
print('''
1. Add Record
2. Display Record
3. Search Record
4. Exit
''')
ch=int(input("Enter your choice:"))
l=[]
if ch==1:
f=open("shoes.dat","ab")
s_id=int(input("Enter Shoes ID:"))
name=input("Enter shoes name:")
brand=input("Enter Brand:")
typ=input("Enter Type:")
price=float(input("Enter Price:"))
l=[s_id,name,brand,typ,price]
pickle.dump(l,f)
print("Record Added Successfully.")
f.close()
elif ch==2:
f=open("shoes.dat","rb")
while True:
try:
dt=pickle.load(f)
print(dt)
except EOFError:
break
f.close()
elif ch==3:
si=int(input("Enter shoes ID:"))
f=open("shoes.dat","rb")
fl=False
while True:
try:
dt=pickle.load(f)
for i in dt:
if i==si:
fl=True
print("Record Found...")
print("ID:",dt[0])
print("Name:",dt[1])
print("Brand:",dt[2])
print("Type:",dt[3])
print("Price:",dt[4])
except EOFError:
break
if fl==False:
print("Record not found...")
f.close()
elif ch==4:
break
else:
print("Invalid Choice")

Output:
1. Add Record
2. Display Record
3. Search Record
4. Exit

Enter your choice:1


Enter Shoes ID:1
Enter shoes name:Power
Enter Brand:Bata
Enter Type:Sports
Enter Price:2000
Record Added Successfully.

1. Add Record
2. Display Record
3. Search Record
4. Exit

Enter your choice:1


Enter Shoes ID:2
Enter shoes name:Sport
Enter Brand:Nike
Enter Type:Sports
Enter Price:5000
Record Added Successfully.

1. Add Record
2. Display Record
3. Search Record
4. Exit

Enter your choice:2


[1, 'Power', 'Bata', 'Sports', 2000.0]
[2, 'Sport', 'Nike', 'Sports', 5000.0]

1. Add Record
2. Display Record
3. Search Record
4. Exit

Enter your choice:3


Enter shoes ID:2
Record Found...
ID: 2
Name: Sport
Brand: Nike
Type: Sports
Price: 5000.0

1. Add Record
2. Display Record
3. Search Record
4. Exit

Enter your choice:

Result:
Thus, the above program to perform following operations into a binary file shoes.dat was executed
successfully.                                             

1. Add record
2. Display records
3. Search record
4. Exit

b) Observe the following code and fill in the given blanks as directed: 4

import mysql.connector as mycon


mydb=mycon.connect(_______________________________________) # Statement 1
mycursor=mydb.___________ # Statemen 2
mycursor.execute(__________________________________________) # Statement 3
mydb._____________ # Statement 4
print(mycursor.rowcount, "record inserted.")
The partial code is given for inserting a record in customer table created . The customer table is given as
following:
i. CustomerID CustomerName City BillAmt MobileNo
111 Abhishek Ahmedabad 1500 9999999999
Write the parameters and values required to fill statement 1. The parameters
values are as follows:

Database Server User Pasword Database


localhost root Sql123 customers

ii. Write function name to create cursor and fill in the gap for statement 2.
iii. Write a query to fill statement 3 with desired values.
iv. Write function to fill statement 4 to save the records into table.

Answer:

import mysql.connector as mycon


mydb=mycon.connect(host="localhost", user="root", password="sql123", database=" customers")# Statement 1
mycursor=mydb.cursor() # Statemen 2
mycursor.execute(“insert into customer values(111,’Abhishek’,’Ahmedabad’,1500,9999999999)”) # Statement 3
mydb.commit() # Statement 4
print(mycursor.rowcount, "record inserted.")

Q – 2 Practical Report File 7


Q – 3 Project 8
Q – 4 Viva Voce 3

Senior School Certificate Examination -2022- 23


Practical Question Paper
Subject: Computer Science(083) Class 12
Time: 3:00 Hours Max. Marks: 30

SET-2
Q-1 a) Write a program to write data into binary file marks.dat and display the records
of students who scored more than 95 marks.
Aim:
To write a program to write data into binary file marks.dat and display the records
of students who scored more than 95 marks.
Program:
import pickle
def search_95plus():
f = open("marks.dat","ab")
while True:
rn=int(input("Enter the rollno:"))
sname=input("Enter the name:")
marks=int(input("Enter the marks:"))
rec=[]
data=[rn,sname,marks]
rec.append(data)
pickle.dump(rec,f)
ch=input("Want more records?Yes:")
if ch.lower() not in 'yes':
break
f.close()
f = open("marks.dat","rb")
cnt=0
try:
while True:
data = pickle.load(f)
for s in data:
if s[2]>95:
cnt+=1
print("Record:",cnt)
print("RollNO:",s[0])
print("Name:",s[1])
print("Marks:",s[2])
except Exception:
f.close()
search_95plus()

Output:
Enter the rollno:1
Enter the name:Kumar
Enter the marks:80
Want more records?Yes:yes
Enter the rollno:2
Enter the name:Ram
Enter the marks:90
Want more records?Yes:yes
Enter the rollno:3
Enter the name:Ravi
Enter the marks:95
Want more records?Yes:yes
Enter the rollno:4
Enter the name:Sathish
Enter the marks:97
Want more records?Yes:no
Record: 1
RollNO: 4
Name: Sathish
Marks: 97
Result:
Thus, the above program was executed successfully.  

b) Observe the following code and fill in the given blanks as directed: 4

import mysql.connector as mycon


mydb=mycon.connect(_______________________________________) # Statement 1
mycursor=mydb.___________ # Statemen 2
mycursor.execute(__________________________________________) # Statement 3
myresult = mycursor.__________ # Statement 4
for x in myresult:
print(x)
The partial code is given for displaying all records from customer table created . The customer table is given as
following:

i. CustomerID CustomerName City BillAmt MobileNo


111 Abhishek Ahmedabad 1500 9999999999
222 Ram kumar Chennai 1501 8888888888
Write the parameters and values required to fill statement 1. The parameters
values are as follows:

Database Server User Pasword Database


localhost root Sql123 customer

ii. Write function name to create cursor and fill in the gap for statement 2.
iii. Write a query to fill statement 3 to display all records from customer table.
iv. Write function to fill statement 4 to fetch all records from customer table.

Answer:
import mysql.connector as mycon
mydb=mycon.connect(host="localhost", user="root", password="sql123", database=" customer")# Statement 1
mycursor=mydb.cursor() # Statemen 2
mycursor.execute(“select * from customers”) # Statement 3
myresult = mycursor.fetchall() # Statement 4
for x in myresult:
print(x)
Q – 2 Practical Report File 7
Q – 3 Project 8
Q – 4 Viva Voce 3

Senior School Certificate Examination -2022- 23


Practical Question Paper
Subject: Computer Science(083) Class 12
Time: 3:00 Hours Max. Marks: 30
SET-3
Q-1 a) Write a program to count a total number of lines and count the total number of
lines starting with 'A', 'B', and 'C' from the file myfile.txt.

Example:
File Contents as given below
Python is super and trending language.
Allows to store the output in the files.
A text file stores textual data.
Binary files can handle binary data.
Binary files use pickle module to store data.
CSV files can handle tabular data.
CSV files can be read easily using CSV reader object.

Program output must be as follows


Total Number of lines are: 7
Total Number of lines starting with A are: 2
Total Number of lines starting with B are: 2
Total Number of lines starting with C are: 2

Aim:
To write a program to count a total number of lines and count the total number of
lines starting with 'A', 'B', and 'C' from the file myfile.txt.

Program:
def lines():
with open(r"F:\SKVV 2022-2023\Class Materials\class 12_Lessons\PRACTICAL 2022-23\SKV 2022-23\Myfile.txt","r") as f1:
data=f1.readlines()
cnt_lines=0
cnt_A=0
cnt_B=0
cnt_C=0
for lines in data:
cnt_lines+=1
if lines[0]=='A':
cnt_A+=1
if lines[0]=='B':
cnt_B+=1
if lines[0]=='C':
cnt_C+=1
print("Total Number of lines are:",cnt_lines)
print("Total Number of lines strating with A are:",cnt_A)
print("Total Number of lines strating with B are:",cnt_B)
print("Total Number of lines strating with C are:",cnt_C)
lines()

Output:
Total Number of lines are: 7
Total Number of lines starting with A are: 2
Total Number of lines starting with B are: 2
Total Number of lines starting with C are: 2
Result:
Thus, the above program was executed successfully.  

b) Observe the following code and fill in the given blanks as directed: 4

import mysql.connector as mycon


mydb=mycon.connect(_______________________________________) # Statement 1
mycursor=mydb.___________ # Statemen 2
mycursor.execute(__________________________________________) # Statement 3
row = mycursor.______________# Statement 4
print(row)
The partial code is given for displaying one record from customer table created . The customer table is given as
following:

i. CustomerID CustomerName City BillAmt MobileNo


111 Abhishek Ahmedabad 1500 9999999999
222 Ram kumar Chennai 1501 8888888888
Write the parameters and values required to fill statement 1. The parameters
values are as follows:

Database Server User Pasword Database


localhost root Sql123 customer

ii. Write function name to create cursor and fill in the gap for statement 2.
iii. Write a query to fill statement 3 to display all records from customer table.
iv. Write function to fill statement 4 to fetch one record from customer table.

Answer:

import mysql.connector as mycon


mydb=mycon.connect(host="localhost", user="root", password="sql123", database=" customer")# Statement
1
mycursor=mydb.cursor() # Statemen 2
mycursor.execute(“select * from customers”) # Statement 3
row = mycursor.fetchone() # Statement 4
print(row)
Q – 2 Practical Report File 7
Q – 3 Project 8
Q – 4 Viva Voce 3

Senior School Certificate Examination -2022- 23


Practical Question Paper
Subject: Computer Science(083) Class 12
Time: 3:00 Hours Max. Marks: 30

SET-4
Q-1 a) Write a program to Create a binary file client.dat to hold records like ClientID, Client name, and 8
Address using the dictionary. Write functions to write data, read them, and print on
the screen.
Aim:
To write a program to create a binary file client.dat to hold records like ClientID, Client name, and
Address using the dictionary. Write functions to write data, read them, and print on
the screen.
Program:
import pickle
rec={}
def file_create():
f=open("client.dat","wb")
cno = int(input("Enter Client ID:"))
cname = input("Enter Client Name:")
address = input("Enter Address:")
rec={cno:[cname,address]}
pickle.dump(rec,f)
f.close()
def read_data():
f = open("client.dat","rb")
print("*"*78)
print("Data stored in File....")
rec=pickle.load(f)
for i in rec:
print(rec[i])
f.close()
while True:
print("1.Enter data")
print("2.Read data")
print("3.Exit")
choice=int(input("Enter you choice"))
if choice==1:
file_create()
elif choice==2:
read_data()
else:
print("Enter valid choice")
break
Output:
1.Enter data
2.Read data
3.Exit
Enter you choice1
Enter Client ID:1
Enter Client Name:Ram
Enter Address:Chennai
1.Enter data
2.Read data
3.Exit
Enter you choice2
******************************************************************************
Data stored in File....
['Ram', 'Chennai']
1.Enter data
2.Read data
3.Exit
Enter you choice3
Enter valid choice

Result:
Thus, the above program was executed successfully.  

b) Observe the following code and fill in the given blanks as directed: 4

import mysql.connector as mycon


mydb=mycon.connect(_______________________________________) # Statement 1
mycursor=mydb.___________ # Statemen 2
mycursor.execute(____________________________________) # Statement 3
mydb.____________# Statement 4
print(mycursor.rowcount, "record(s) affected")

The partial code is given for to update records in table. The customer table is given as following:

i. CustomerID CustomerName City BillAmt MobileNo


111 Abhishek Ahmedabad 1500 9999999999
222 Ram kumar Chennai 1501 8888888888
Write the parameters and values required to fill statement 1. The parameters
values are as follows:

Database Server User Pasword Database


localhost root Sql123 customer

ii. Write function name to create cursor and fill in the gap for statement 2.
iii. Write a query to fill statement 3 to update records with City = 'Delhi' for CustomerName=’Abhishek’ in
customer table.
iv. Write function to fill statement 4 to save the records into table.
Answer:
import mysql.connector as mycon
mydb=mycon.connect(host="localhost", user="root", password="sql123", database=" customer")# Statement 1
mycursor=mydb.cursor() # Statemen 2
mycursor.execute("UPDATE customer SET City = 'Delhi' where CustomerName=’Abhishek’”) # Statement 3
mydb.commit() # Statement 4
print(mycursor.rowcount, "record(s) affected")
Q – 2 Practical Report File 7
Q – 3 Project 8
Q – 4 Viva Voce 3

Senior School Certificate Examination -2022- 23


Practical Question Paper
Subject: Computer Science(083) Class 12
Time: 3:00 Hours Max. Marks: 30

SET-5
Q-1 a) Write a program to add students details in CSV file students.csv as mentioned in below table format ,
and print them with tab delimiter. Ignore first row header to print in tabular form.
Field 1 Data Type
StudentID Integer
StudentName String
Score Integer
Aim:
To write a program to add students details in CSV file students.csv as mentioned in below table
format , and print them with tab delimiter. Ignore first row header to print in tabular form.
Program:
from csv import writer,reader
def addrecord():
#Create Header First
f = open("result.csv","w",newline='\n')
dt = writer(f)
dt.writerow(['Student_ID','StudentName','Score'])
f.close()
#Insert Data
f = open("result.csv","a",newline='\n')
while True:
st_id= int(input("Enter Student ID:"))
st_name = input("Enter Student name:")
st_score = input("Enter score:")
dt = writer(f)
dt.writerow([st_id,st_name,st_score])
ch=input("Want to insert More records?(y or Y):")
ch=ch.lower()
if ch !='y':
break
print("Record has been added.")
f.close()

def viewrecord():
f = open("result.csv","r")
dt = reader(f,delimiter=',')
data = list(dt)
f.close()
for i in data:
for j in i:
print(j,"\t",end=" ")
print()
addrecord()
viewrecord()

Output:
Enter Student ID:1
Enter Student name:Ram
Enter score:100
Want to insert More records?(y or Y):y
Enter Student ID:2
Enter Student name:Kumar
Enter score:95
Want to insert More records?(y or Y):n
Record has been added.
Student_ID StudentName Score
1 Ram 100
2 Kumar 95

Result:
Thus, the above program was executed successfully.  
b) Observe the following code and fill in the given blanks as directed: 4

import mysql.connector as mycon


mydb=mycon.connect(_______________________________________) # Statement 1
mycursor=mydb.___________ # Statemen 2
mycursor.execute() Statemen 3
mydb.__________Statement 4
print(mycursor.rowcount, "record(s) affected")

The partial code is given for deleting a record from customer table created . The customer table is given as
following:

i. CustomerID CustomerName City BillAmt MobileNo


111 Abhishek Ahmedabad 1500 9999999999
222 Ram kumar Chennai 1501 8888888888
Write the parameters and values required to fill statement 1. The parameters
values are as follows:

Database Server User Pasword Database


localhost root Sql123 customers

ii. Write function name to create cursor and fill in the gap for statement 2.
iii. Write a query to fill statement 3 to delete records with City = 'Chennai' from customer table.
iv. Write function to fill statement 4 to save the records into table.

Answer:
import mysql.connector as mycon
mydb=mycon.connect(host="localhost", user="root", password="sql123", database=" customers")# Statement 1
mycursor=mydb.cursor() # Statemen 2
mycursor.execute("DELETE FROM customer WHERE CustomerName=‘Abhishek’ ")
print(“mycursor.rowcount, "record(s) affected")”) # Statement 3
mydb.commit() # Statement 4
print(mycursor.rowcount, "record(s) affected")
Q – 2 Practical Report File 7
Q – 3 Project 8
Q – 4 Viva Voce 3

Senior School Certificate Examination -2022- 23


Practical Question Paper
Subject: Computer Science(083) Class 12
Time: 3:00 Hours Max. Marks: 30

SET-6
Q-1 a) Write a program to Create a binary file student.dat to hold students’ records like Rollno., Students
name, and Address using the list. Write functions to write data, read them, and print on the screen.
Aim:
To write a program to Create a binary file student.dat to hold students’ records like Rollno., Students
name, and Address using the list. Write functions to write data, read them, and print on the screen.

Program:
import pickle
rec=[]
def addrecord():
f=open("student.dat","wb")
rno = int(input("Enter Student No:"))
sname = input("Enter Student Name:")
address = input("Enter Address:")
rec=[rno,sname,address]
pickle.dump(rec,f)
def viewrecord():
f = open("student.dat","rb")
print("*"*78)
print("Data stored in File....")
rec=pickle.load(f)
for i in rec:
print(i)
addrecord()
viewrecord()

Output:
Enter Student No:1
Enter Student Name:Ram
Enter Address:Chennai
******************************************************************************
Data stored in File....
1
Ram
Chennai

Result:
Thus, the above program was executed successfully.  

b) Observe the following code and fill in the given blanks as directed: 4

import ___________ as mycon # Statement 1


mydb=mycon.connect(______________________) # Statement 2
mycursor=mydb._____________# Statement 3
mycursor.execute(________________________________) Statement 4
The partial code is given for creating customer table with following structure:

Fields Datatype Length Constrain


CustomerID Integer 3 Primary key
CustomerName Char 20 --
City Char 15 --
BillAmt Float -- --
MobileNo Numeric 10 --
i. Write name of the module to fill statement 1 to be imported.
ii. Write the parameters and values required to fill statement 2. The parameters
values are as follows:

Database Server User Pasword Database


localhost root Sql123 customers

iii. Write function name to create cursor and fill in the gap for statement 3.
iv. Write a query to fill statement 4 to create customer table as mentioned in table structure.

Answer:
import mysql.connector as mycon # Statement 1
mydb=mycon.connect(host="localhost", user="root", password="sql123",database=”customers”) # Statement 2
mycursor=mydb.cursor()# Statemen 3
mycursor.execute(“create table customer(CustomerID int (3) primary key, CustomerName char (20), City char
(15),BillAmt float,MobileNo integer (10))”) Statemen 4

Senior School Certificate Examination -2022- 23


Practical Question Paper
Subject: Computer Science(083) Class 12
Time: 3:00 Hours Max. Marks: 30

SET-7
Q-1 a) Write a program to  read a text file my_file.txt and display the number of
vowels/consonants/uppercase/lowercase characters in the file.
Aim:
To write a program to  read a text file my_file.txt and display the number of
vowels/consonants/uppercase/lowercase characters in the file.

Example:
File Contents as given below
Python is super and trending language.
Allows to store the output in the files.
A text file stores textual data.

Program output must be as follows


Vowels: 35
Consonants: 58
Uppers: 3
Lowers: 87

Program:
f=open(r"F:\SKVV 2022-2023\Class Materials\class 12_Lessons\PRACTICAL 2022-23\SKV 2022-23\my_file.txt")
d=f.read()
v=0
c=0
u=0
l=0
for i in d:
if i.isupper():
u+=1
elif i.islower():
l+=1
if i.lower() in 'aeiou':
v+=1
elif i.isspace():
pass
elif i.lower() not in 'aeiou':
c+=1
print("Vowels:",v)
print("Consonants:",c)
print("Uppers:",u)
print("Lowers:",l)
f.close()
Output:
Vowels: 35
Consonants: 58
Uppers: 3
Lowers: 87
Result:
Thus, the above program was executed successfully.  

b) Observe the following code and fill in the given blanks as directed: 4

import ___________ as mycon # Statement 1


mydb=mycon.connect(______________________) # Statement 2
mycursor=mydb._____________# Statement 3
mycursor.execute(________________________________) Statement 4
The partial code is given for creating database “Customers”.
i. Write name of the module to fill statement 1 to be imported.
ii. Write the parameters and values required to fill statement 2. The parameters
values are as follows:

Database Server User Pasword


localhost root Sql123

iii. Write function name to create cursor and fill in the gap for statement 3.
iv. Write a query to fill statement 4 to create database Customers.

Answer:
import mysql.connector as mycon # Statement 1
mydb=mycon.connect(host="localhost", user="root", password="sql123") # Statement 2
mycursor=mydb.cursor() # Statement 3
mycursor.execute(“Create database Customers”) Statement 4

You might also like