CBSE class 12 computer science practical paper 2024 with solution
AISSCE Practical Examination 2024
COMPUTER SCIENCE (083)
Time : 3 Hours M.M. 30
Q1. 8
(i) Write a user defined function countlines() in Python to count and display the number of lines starting with ”#’ in a text file “data.txt”.
(ii) A binary file “hospital.dat” has structure [Patientid, PatientName, Disease].
a) Write a user defined function CreateRecord() to input data for a record and add it to hospital.dat .
b) Write a user defined function DisplayRecord() in Python to display those records from “hospital.dat” where Disease is fever or cough.
Q2. 4
The code given below inserts the following record in the table Employee:
Idno– integer
EmpName – string
Designation – string
Salary – integer
Note the following to establish connectivity between Python and MYSQL:
- Username is root
- Password is root
- The table exists in a MYSQL database named Employees.
- The details (Idno, EmpName, Designation and Salary) are to be accepted from the
Write the following missing statements to complete the code: 2+3
Statement 1 – to form the cursor object
Statement 2 – to execute the command that inserts the record in the table Employee.
Statement 3- to add the record permanently in the database
Statement 4- to close the database connection.
import mysql.connector as mysql
def sql_data():
con=mysql.connect(host=”localhost”,user=”root”, password=”root”, database=”Employees”)
mycursor= #Statement 1
Idno=int(input(“Enter ID Number :: “))
EmpName=input(“Enter Employee Name :: “)
Designation= input(“Enter Designation”)
Salary=int(input(“Enter Salary :: “))
query=”insert into Employee values({},'{}’,{},{})”.format(Idno,EmpName,Designation,Salary)
____________________________ #Statement 2
_____________________________ # Statement 3
print(“Data Added successfully”)
____________________________ #Statement 4
Q3.Practical File 7
Q4.Project File 8
Q5.Viva-Voce 3
Solution:
Q1
i.
def countlines():
f=open(“data.txt”,”r”)
count=0
data=f.readlines()
for d in data:
if d[0]]== ‘#’:
count+=1
print(‘Number of lines starting with #=’,count)
f.close()
ii
(a)
import pickle
def CreateRecord():
f=open(“hospital.dat”,”ab”)
Patientid=int(input(“Enter Patient id: “))
Patient EmpName=input(“Enter Name of Patient:”)
Disease= input(“Enter Disease:”)
record=[Patientid, PatientName,Disease]
pickle.dump(record, f)
f.close()
(b)
def DisplayRecord():
f=open(“hospital.dat”,”rb”)
try:
while True:
rec=pickle.load(f)
if rec[2]==’fever’ or rec[2]==’cough’:
print(record)
except:
f.close()
Q2.
#Statement 1 – conn.cursor()
#Statement 2 – mycursor.execute(query)
#Statement 3 – conn.commit()
#Statement 4 – conn.close()
Class xii computer science practical paper -1
Class xii computer science Sample paper 2023 with solutions
Class xii computer science project file
Class 12 Computer Science Practical File
Click here for Quiz on Python Basics