# Solution Computer Science Practical Paper 2023 Class 12

#### Bytutorialaicsip

Dec 31, 2022

In this article you will get Solution Computer Science Practical Paper 2023 Class 12. Here we go!

Topics Covered

## Solution Computer Science Practical Paper 2023 Class 12

If you are looking for the practical question paper computer science class 12 follow this link:

Let us start with the solution for practical question paper for computer science class 12.

## Solution Computer Science Practical Paper 2023 Class 12 Set 1

Here is the soultion for computer science practical paper 2023 class 12 set 1.

### Q – 1 Python Program on Data File handling (Binary File)

Q – 1 a) Write a menu drive program to perform following operations into a binary file shoes.dat.

2. Display records
3. Search record
4. Exit

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

Solution:

``````import pickle
while True:
print('''
2. Display Record
3. Search Record
4. Exit
''')
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)
f.close()
elif ch==2:
f=open("shoes.dat","rb")
while True:
try:
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:
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:
f.close()
elif ch==4:
break
else:
print("Invalid Choice")``````

### Q -2 Stub Program

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

``````import mysql.connector as mycon
cn=mycon.connect(_______________________________________) # Statement 1
cr=cn.___________ # Statemen 2
cust_id=int(input(“Enter ID:”))
cust_name=input(“Enter Customer Name:”)
city=input(“Enter City:”)
ba=float(input(“Enter Bill Amount:”))
mno=input(“Enter Mobile No.:”)
cr.execute(__________________________________________) # Statement 3
cn._____________ # Statement 4``````

Solution:

Ans. 1:

Ans. 2:

cursor

Ans. 3:

“insert into customer values ({},'{}’,'{}’,{},'{}'”.format(cust_id,cust_name,city,ba,mno)

OR

“insert into customer values(%d,’%s’,’%s’,%f,’%s’)”%cust_id,cust_name,city,ba,mno

Ans. 4:

commit()

### Q – 3 Project

The project report should be submitted with complete code and outputs.

### Q – 4 Viva Voce

The oral questions can be asked based on the project report and practical file.

## Solution Computer Science Practical Paper Class 12 Set 2

Let us see another soultion computer science practical paper class 12 set 2. Her we go!

### Q – 1 Stack Program (8 Marks)

Q – 1 a) Write a menu drive program in python to implement stack using a list and perform following functions:

1. Push
2. Pop
3. Display
4. Peek
5. Exit

Solution:

``````stk=[]
top=-1
def isEmpty():
global stk
if stk==[]:
print("Stack is Empty")
else:
None
def push():
global stk
global top
n=int(input("Enter value to append:"))
stk.append(n)
top=len(stk)-1
print("Value is Pushed into stack.")

def display():
global stk
global top
if top==-1:
isEmpty()
else:
top=len(stk)-1
print("Top->",stk[top])
for i in range(top-1,-1,-1):
print(stk[i])

def Pop():
global stk
global top
if top==-1:
isEmpty()
else:
print("Elment Popped:",stk.pop())
top=top-1

def peek():
global stk
global top
top=len(stk)-1
print("Peeked Element:",stk[top])
while True:
print('''
1. Push
2. Pop
3. Display
4. Peek
5. Exit
''')
ch=int(input("Enter any number:"))
if ch==1:
push()
elif ch==2:
Pop()
elif ch==3:
display()
elif ch==4:
peek()
elif ch==5:
print("Bye Bye!")
break
else:
print("Invalid choice")

### Q – 2 Stub Program

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

``````import mysql.connector as mycon
cn=mycon.connect(_______________________________________) # Statement 1
cr=cn.___________ # Statemen 2
cust_id=int(input(“Enter ID to Update:”))
cust_name=input(“Enter Customer Name (New):”)
city=input(“Enter City (New):”)
ba=float(input(“Enter Bill Amount (New):”))
mno=input(“Enter Mobile No.(New):”)
cr.execute(__________________________________________) # Statement 3
cn._____________ # Statement 4``````

The partial code is given for update a record in customer table created in Rajwadi Store. The customer table is given as following:
CustomerID – 111
CustomerName – Abhishek
BillAmt – 1500
MobileNo – 9999999999
i. Write the parameters and values required to fill statement 1. The parameters values are as follows:

Ans.:

``cn=mycon.connect(host="main_rajwadi", user="rajwadi_admin", passwd="Rajwadi@2023", database = "rajwadi")``

ii. Write function name to create cursor and fill in the gap for statement 2.

Ans.:

``cn.cursor()``

iii. Write a query to fill statement 3 with desired values.

Ans.:

``cr.execute("update customer set customername='{}', city='{}', billamt={}, mobileno='{}' where customerid={}.format(cust_name, city, ba, mno,cust_id)")``

iv. Write a query to fill statement 4 to save the records into table.

Ans.:

cn.commit()

## Solution Computer Science Practical Paper Class 12 Set 3

Here we are going to discuss solution for Computer Science Practical Paper Class 12 set 3. Here we go!

### Python Program

Q – 1 a) Write a menu drive program to perform following operations into telephone.csv.

2. Display records
3. Search record
4. Exit
The structure of file content is: [s_id, name, brand, type, price]
``````import csv
f=open("telephone.csv",'a',newline='')
wo=csv.writer(f)
s_id=int(input("Enter Subscriber ID:"))
name=input("Enter name of subscriber:")
brand=input("Enter brand of telephone:")
typ=input("Enter customer type:")
price=float(input("Enter Price:"))
wo.writerow([s_id,name,brand,typ,price])
f.close()

def display_record():
f=open("telephone.csv",'r')
l=list(ro)
for i in range(1,len(l)):
print(l[i])
f.close()

def search_record():
f=open("telephone.csv","r")
sid=input("Enter id to search:")
found=0
for i in ro:
if sid==i[0]:
found=1
print("Record Found:")
print(i)
if found==0:
f.close()
while True:
print('''
2. Display record
3. Search record
4. Exit
''')
if ch==1:
elif ch==2:
display_record()
elif ch==3:
search_record()
elif ch==4:
print("Thank you, See you again!!")
break
else:
print("Invalid Choice")
``````

### Stub Program

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

``````import mysql.connector as mycon
cn=mycon.connect(_______________________________________) # Statement 1
cr=cn.___________ # Statemen 2
cust_id=int(input(“Enter ID to Delete:”))
cr.execute(__________________________________________) # Statement 3
cn._____________ # Statement 4``````

The partial code is given for delete a record from customer table created in Rajwadi Store.
The customer table is given as following:

i. Write the parameters and values required to fill statement 1. The parameterv alues are as follows:

Ans.:

``cn=mycon.connect(host="main_rajwadi", user="rajwadi_admin", passwd="Rajwadi@2023", database = "rajwadi")``

ii.Write function name to create cursor and fill in the gap for statement 2.

Ans.:

``cn.cursor()``

iii. Write a query to fill statement 3 with desired values.

Ans.:

``cur.execute("delete from customer where customerid={}.format(cust_id)")``

iv. Write a query to fill statement 4 to save the records into table.

Ans.:

cn.commit()

## Solution Computer Science Practical Paper Class 12 Set 4

Let us discuss solution computer science practical paper class 12 set 4.

### Python Program

Q – 1 a) WAP a menu-driven program in python to implement following on binary file of the given structure:
[Doctor_Id, Doctor_Name, Hospital_Id,Joining_Date,Speciality,Salary]

1. Write a record to the file
2. Read all the records to the file
3. Update Record
4. Exit
``````import pickle

def insertRec():
doctor_id = int(input('Enter doctor id:'))
doctor_name = input('Enter Name:')
hospital_id = int(input('Enter hosptial id:'))
joining_date=input("Enter date:")
speciality=input("Enter speciality:")
salary=float(input("Enter Salary:"))

rec = [doctor_id,doctor_name,hospital_id,joining_date,speciality,salary]

f = open('hospital.dat','ab')
pickle.dump(rec,f)
f.close()

f = open('hospital.dat','rb')
while True:
try:
print(rec)
except EOFError:
break
f.close()

def updaterec():
f = open('hospital.dat','rb')
r1 = []
while True:
try:
r1.append(r)
except EOFError:
break
f.close()
print(r1)
d_id=int(input("Enter doctor id to update:"))
found=0
doctor_name = input('Enter new Name:')
hospital_id = int(input('Enter new hosptial id:'))
joining_date=input("Enter new date:")
speciality=input("Enter new speciality:")
salary=float(input("Enter new Salary:"))
for i in range (len(r1)):
if r1[i][0]==d_id:
found=1
r1[i][1] = doctor_name
r1[i][2]=hospital_id
r1[i][3]=joining_date
r1[i][4]=speciality
r1[i][5]=salary
f = open('hospital.dat','wb')
for x in r1:
pickle.dump(x,f)
f.close()
if found==0:
while True:
print('''
1. Write a record to the file
2. Read all the records to the file
3. Update Record
4. Exit
''')
ch = int(input('Enter you choice:'))
if ch == 1:
insertRec()
elif ch == 2:
elif ch == 3:
updaterec()
elif ch == 4:
print("Thank you, visit again!")
break
``````

### Stub Program

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

``````import mysql.connector as mycon
cn=mycon.connect(___________________________) # Statement 1
cr=cn. # Statemen 2
cr.execute(_______________________________) # Statement 3
dt=cr._ # Statement 4
for i in dt:
print(i)``````

The partial code is given for display all records from customer table created in Rajwadi Store.
The customer table is given as following:

i. Write the parameters and values required to fill statement 1. The parameterv alues are as follows:

Ans.:

``cn=mycon.connect(host="main_rajwadi", user="rajwadi_admin", passwd="Rajwadi@2023", database = "rajwadi")``

ii.Write function name to create cursor and fill in the gap for statement 2.

Ans.:

``cn.cursor()``

iii. Write a query to fill statement 3 with desired values.

Ans.:

``cur.execute("selet * from customer")``

iv. Write a function to fill statement 4 to store the records in list object dt.

Ans.:

``cr.fetchall()``

## Solution Computer Science Practical Paper Class 12 Set 5

Let us see now solution computer science practical paper class 12 set 5. Here it is:

### Python Program

Q – 1 a) Write a program to create CSV file and store empno, name and salary of employee. Display the records whose salary in range of 5000 to 15000.

``````import csv
def create_csv():
f=open("emp.csv",'w',newline='')
wo=csv.writer(f)
n=int(input("How many records?:"))
for i in range(n):
empno=int(input("Enter employee number:"))
ename=input("Enter Ename:")
salary=float(input("Enter Salary:"))
wo.writerow([empno,ename,salary])
print("Record file created Successfully.")
f.close()

def display_record():
f=open("emp.csv",'r')
for i in ro:
if float(i[2])>=5000 and float(i[2])<=15000:
print(i)
f.close()
create_csv()
display_record()
``````

### Stub Program

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

``````import mysql.connector as mycon
cn=mycon.connect(_______________________________________) # Statement 1
cr=cn.___________ # Statemen 2
cr.execute(__________________________________________) # Statement 3
dt=cr._____________ # Statement 4
for i in dt:
print(i)``````

The partial code is given for display all records from customer table whose bill amount is more than 5000.
The customer table is given as following:

i. Write the parameters and values required to fill statement 1. The parameterv alues are as follows:

Ans.:

``cn=mycon.connect(host="main_rajwadi", user="rajwadi_admin", passwd="Rajwadi@2023", database = "rajwadi")``

ii.Write function name to create cursor and fill in the gap for statement 2.

Ans.:

``cn.cursor()``

iii. Write a query to fill statement 3 with desired values.

Ans.:

``cr.execute("select * from customer where billamt>5000")``

iv. Write a function to fill statement 4 to store all the tuples in a list object dt.

``cur.fetchall()``