Preview
Computer science practical paper 2023 class 12 with solution
AISSCE Practical Examination 2021
COMPUTER SCIENCE (083)
Time : 3 Hours M.M. 30
Q1. 8
(i) Write a user defined function countwords() in Python to count and display the number of times words “this” and “that” appear in a text file “data.txt”.
(ii) Write a user defined function countdigits() in Python to count and display the number of digits from a text file “data.txt”.
OR
(i) ADD() – To accept and add data of an employee to a CSV file ‘emp.csv’. Each record consists of a list with field elements as empid, name and salary to store employee id, employee name and employee salary
(ii) COUNTR() – To count the number of records present in the CSV file named ‘emp.csv’.
Q2. 4
The code given below inserts the following record in the table Shop:
Itemno– integer
ItemName – string
Description – string
Price – 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 DATA.
- The details (Itemno, ItemName, Description and price) are to be accepted from the user
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(): connection1=mysql.connect(host=”localhost”,user=”root”, password=”root”, database=”DATA”) cur= #Statement 1 Itemno=int(input(“Enter Itemno :: “)) ItemName=input(“Enter ItemName :: “) Description= input(“Enter Description::”) Price=int(input(“Enter Price:: “)) query=”insert into Shop values({},'{}’,{},{})”.format(Itemno,ItemName,Description,Price) ____________________________ #Statement 2 _____________________________ # Statement 3 print(“Record Added successfully”) ____________________________ #Statement 4
Q3.Practical File 7
Q4.Project File 8
Q5.Viva-Voce 3
Solution:
Q1
i.
def countwords(): f=open("data.txt","r") countthis=0 countthat=0 data=f.readlines() for d in data: word=d.split() for w in words: if w=='this': countthis+=1 if w=='this': counthat+=1 print(‘Number of times "this" appears=’,countthis) print(‘Number of times "that" appears=’,countthat) f.close()
ii
def countdigits(): f=open("data.txt","r") count=0 data=f.read() for d in data: if d.isdigit(): count+=1 print(‘Number of Digits=’,count) f.close()
OR
(i)
import csv def ADD(): f=open(‘emp.csv’,’a’,newline=”) w=csv.writer(f) empid=int(input(‘Enter employee id=’)) name=input(‘Enter employee name=’) salary=float(input(‘Enter salary =’)) rec=[empid,name,salary] w.writerow(rec) f.close() (ii)
def COUNTR(): f=open(‘emp.csv’,’r’) r=csv.reader(f) count=0 for rec in r: count+=1 print(‘Number of records=’,count) f.close()
Q2.
#Statement 1 – connection1.cursor() #Statement 2 – cur.execute(query) #Statement 3 – connection1.commit() #Statement 4 – connection1.close()
Class xii computer science practical paper -1
Class xii computer science practical paper -2
Class xii computer science Sample paper 2023 with solutions
Class xii computer science project file
Class 12 Computer Science Practical File
Popular Books of Computer Science