CS Practicalpractice Questionssolutionfor Board Exam
CS Practicalpractice Questionssolutionfor Board Exam
FOR
PRACTICAL EXAMINATION (2024-25)
SUBJECT: COMPUTER SCIENCE (083)
Class XII
PYTHON PROGRAMMING
Program 01. Write a program using user defined function count_line() that count the number of lines
starting with letter ‘A’ or ‘T’ from the file “data.text” and display it on the screen.
Solution:-
def count_line():
fp = open("data.txt","r")
c =0
ln=fp.readline()
while ln:
if ln[0] =='A' or ln[0] =='T':
c = c+1
ln = fp.readline()
fp.close()
return c
#main
p =count_line()
print("Number of lines atarting with letter 'A' or 'T' = ",p)
Program 02. Write a program using user defined function in Python WordCount() to read a text file
“Mydiary.txt” and display the number of words present in each line.
Example:
If the file content is as follows:
This is my program
We are learning Python language
The function should display the output as:
Line No 1 : Words=4
Line No 2 : Words=5
Solution:
def word_count():
fp = open("mydiary.txt","r")
L=fp.readlines()
c=1
for i in L:
s=i.split(" ")
print("Line No:",c,": Words=",len(s))
c=c+1
fp.close()
#main()
word_count()
Program 03. Write a program using user defined function CopyBinary() that will copy the data from the
binary file "source.dat" to "target.dat" Consider the binary file “source.dat” that contains the
information of employees like (eid, ename, salary) in form of list.
Solution:-
def CopyBinary():
import pickle as pl
try:
f1 = open("dps.dat", "rb")
f2 = open("bhel.dat", "wb")
while True:
L = pl.load(f1)
pl.dump(L,f2)
except FileNotFoundError:
print("File name does not exist")
except EOFError:
print("Successfully copied")
f1.close()
f2.close()
#main
CopyBinary()
Program 04. Write a method/function Count_Lines() in python to read lines from a text file Report.txt, and
display the lines which are not starting with vowel.
For example: If the text file Report.txt contents are as follows:
An apple a day keeps the doctor away.
We all pray for everyone’s safety.
It is very easy and simple language.
Thanks for your feedback.
Then, Output will be:
We all pray for everyone’s safety.
Thanks for your feedback.
Solution:
def display_line():
fp = open("Report.txt","r")
c =0
ln=fp.readlines()
for i in ln:
if i[0] not in "AEIOUaeiou":
print(i)
fp.close()
#main
display_line()
SQL Queries
Q1. Write the SQL commands for the question from (i) to (iv) on the basis of table TEACHER given below:
Table : TEACHER
TNo Tname Gender Age Department Salary DOB
101 Ashok Kumar M 28 English 15000 2010-10-13
102 Rakesh Sharma M 32 Mathematics 25000 2008-08-23
103 Richa Saini F 27 Computer 22000 2014-07-15
104 Amit Gupta M 35 Science 17000 NULL
105 Sandeep Goyal M 42 Computer 19000 2005-12-27
106 Sangeeta F 33 English 14000 2008-11-17
107 Jyoti Sharma F 29 Hindi 12000 2012-05-13
108 Manoj Kumar M 40 Science 21000 NULL
109 Rajendra Kapoor M 36 Art 16000 2004-04-25
110 Vinay Kumar M 32 English 18000 2011-03-10
(iii) To add a new column PhoneNo in the above table to store the phone number of teacher.
ALTER TABLE TEACHER ADD PHONENO INT(11);
(iv) To increase the salary of all the teachers by 3000.
UPDATE TEACHER SET SALARY=SALARY+3000;
Q2. Write the SQL commands for the question from (i) to (iv) on the basis of table COACH given below:
Table : COACH
CoachID CoachName Age Sports DOB Fee Gender
101 KUKREJA 35 KARATE 1996-03-27 1000 M
102 RAVINA 34 KARATE 1992-01-20 1200 F
103 KARAN 34 SQUASH NULL 2000 M
104 TARUN 33 BASKETBALL 1998-02-19 1500 M
105 AMIT 36 SWIMMING 1998-01-12 750 M
106 RAHUL 36 SWIMMING 1990-02-24 800 M
107 DEEPAK 39 SQUASH NULL 2200 M
108 MOHIT 39 KARATE 1998-02-22 1100 M
109 SHALINI 37 SWINMMING NULL 900 F
110 SEEMA 41 BASKETBALL 1997-02-19 1700 F
111 ABHISHEK 37 FOOTBALL 1996-02-15 1100 M
Q3. Write the SQL commands for the question from (i) to (iv) on the basis of table TEACHER given below:
Table : TEACHER
TNo Tname Gender Age Department Salary DOB
101 Ashok Kumar M 28 English 15000 2010-10-13
102 Rakesh Sharma M 32 Mathematics 25000 2008-08-23
103 Richa Saini F 27 Computer 22000 2014-07-15
104 Amit Gupta M 35 Science 17000 NULL
105 Sandeep Goyal M 42 Computer 19000 2005-12-27
106 Sangeeta F 33 English 14000 2008-11-17
107 Jyoti Sharma F 29 Hindi 12000 2012-05-13
108 Manoj Kumar M 40 Science 21000 NULL
109 Rajendra Kapoor M 36 Art 16000 2004-04-25
110 Vinay Kumar M 32 English 18000 2011-03-10
(i) To display the details of all teachers in ascending order of their salary.
SELECT * FROM TEACHER ORDER BY SALARY;
(ii) To display the detail of the teachers whose name starts with letter ‘R’.
SELECT * FROM TEACHER WHERE TNAME LIKE ‘R%’;
(iii) To remove the column Gender from the above table.
ALTER TABLE TEACHER DROP COLUMN GENDER;
(iv) To display department name and the average salary of each department.
SELECT DEPARTMENT, AVG(SALARY) FROM TEACHER GROUP BY DEPARTMENT;
Q4. Write the SQL commands for the question from (i) to (iv) on the basis of table COACH given below:
Table : COACH
CoachID CoachName Age Sports DOB Fee Gender
101 SANJEEV 35 KARATE 1996-03-27 1000 M
102 RAVINA 34 KARATE 1992-01-20 1200 F
103 KARAN 34 SQUASH NULL 2000 M
104 TARUN 33 BASKETBALL 1998-02-19 1500 M
105 AMIT 36 SWIMMING 1998-01-12 750 M
106 RAHUL 36 SWIMMING 1990-02-24 800 M
107 DEEPAK 39 SQUASH NULL 2200 M
108 MOHIT 39 KARATE 1998-02-22 1100 M
109 SHALINI 37 SWIMMING NULL 900 F
110 SEEMA 41 BASKETBALL 1997-02-19 1700 F
111 ABHISHEK 37 FOOTBALL 1996-02-15 1100 M