You are on page 1of 76

KENDRIYA VIDYALAYA

AMBARNATH
PRACTICAL LIST 2023-24
CLASS: XII
SUB: COMPUTER SCIENCE
KENDRIYA VIDYALAYA AMBARNATH
PRACTICAL LIST
CLASS: XII
SUB: COMPUTER SCIENCE
SESSION 2023-24
Index
Sr.
Name of the Experiment/Activity
No.

1. Write a function to check prime, calculate factorial and Fibonacci series.

2. Program to perform various operations on the list.

3. Program to read a text file and count and display different types of characters in the file.
4. Write a Python program to find smallest word, biggest word words of specific length, count the occurrence of specific words from a
text file.
5. Write a program to read text file and display and count different lines from text file.

6. Write a program to append, count and display specific records in text file.

7. Write a program to modify contents of the text file and copy contents from one file to another file based on condition.

8. Write a program to create a binary file using list and perform search operation on it.

9. Write a program to create a binary file using dictionary and perform read, append and search operations on it.

10. Write a program to perform update operation on the binary file.


11. Write a program to perform delete operation on the binary file.

12. Write a menu driven program to create csv file and append student records such as roll number, marks, total and percentage.

13. Write a program to create csv file and perform search operation on csv file using different criteria.

14. Write a program to copy contents containing phonebook of a csv file into another csv file.

15. Write a program to implement stack in Python using list and perform Push and Pop operations on it.

16. Implementation of various SQL commands on different tables in SQL database.


17. Write a program to connect with database, create table student, store records of students and display records.

18. Integrate MySQL with Python by importing the MySQL module to search student using rollno, name, age, class and if present in
table display the record, if not display appropriate method.

19. Write a program to connect with database and update and delete the record from database.

20 SQL Queries Set 1 (Database Fetching records)

21 SQL Queries Set 2 (Based on Functions)

22 SQL Queries Set 3 (DDL Commands)

23 SQL Queries set 4 (Based on Two Tables)


Practical 1-Write a function to check prime, calculate
factorial and Fibonacci series.
Solution:
#code continue
Output:
Practical 2-Program to perform following operations on the list-
1. To find sum and average of the list
2. Double the odd values and half even values of a list
3. Left shift operation on list by given number
4. Right shift operation on list by given
number Solution:
#function call
Output:
Practical 3-Read a text file and display the number of digits, alphabets, vowels,
consonants, uppercase , lowercase characters, spaces and other characters in the
file.
Solution:
Output:
Practical 4-Write a Python program to find smallest word, biggest word
words of specific length, count the occurrence of specific words from a
text file.
Solution:
Output:
Program 5- Write a program to perform following operations on text file
1. Display 1st and last line of file
2. Read the file contents line by line with each word separated by #
3. Count and display lines start with 'O' or 'o'
4. Count and display line end
with 'a' Solution:
Output:
Program 6- Write a program to append, count and display specific
records in text file.
Solution:
Output:
#Practical 7- Write a program to modify contents of the file and copy
contents from one file to another file based on condition.
#Solution:
Output:
Practical 8-Write a program to create a binary file with roll number and
name using list. Search for a given roll number and display the name, if
not found display appropriate message.
Solution:
Output:
#Practical 9-Write a program to create a binary file using dictionary
and perform read, append and search operations on it.
#Solution
Output:
Practical 10-Write a program to create a binary file with roll number,
name, and marks and update the binary file by input a roll number and
updates the marks.
Solution:
Output:
Practical 11-Write a program to create a binary file with roll number,
name and mark and delete a particular record.
Solution:
Output:
#Practical 12-Write a menu driven program to create csv file and append
student records such as roll number, marks, total and percentage.
Solution:
Output:
Practical 13-Write a program to create csv file and perform search
operation on csv file using different criteria.
Solution:
Output:
#Practical 14-Write a program to copy contents containing phonebook of
a csv file into another csv file.
Solution:
Output:
Practical 15-Write a program to implement stack in Python using list and
perform Push and Pop operations on it.
Solution:
Output:
Practical 16- Implementation of various SQL commands on the table.
Solution:

Table : Teacher
T_ID Name Age Department Date_of_join Salary Gender
1 Jugal 34 Computer Sc 10/01/2017 12000 M
2 Sharmila 31 History 24/03/2008 20000 F
3 Sandeep 32 Mathematics 12/12/2016 30000 M
4 Sangeeta 35 History 01/07/2015 40000 F
5 Rakesh 42 Mathematics 05/09/2007 25000 M
6 Shyam 50 History 27/06/2008 30000 M
7 Shiv Om 44 Computer Sc 25/02/2017 21000 M
8 Shalakha 33 Mathematics 31/07/2018 20000 F

Table : Posting
P_ID Department Place
1 History Agra
2 Mathematics Raipur
3 Computer Science Delhi

mysql> use s1;


Database changed
mysql> create table teacher(T_ID int, Name varchar(10),Age int,
Department varchar(15),Date_of_join date, Salary int, Gender char(1));
mysql> insert into teacher values(1,'Jugal',34,'Computer Sc','2017-01-
10',12000,'M');
mysql> insert into teacher values(2,'Sharmila',31,'History','2018-03-
24',20000,'F');
mysql> insert into teacher values(3,'Sandeep',32,'Mathematics','2016-12-
12',30000,'M');

mysql> insert into teacher values(4,'Sangeeta',35,'History','2015-07-


01',40000,'F');
mysql> insert into teacher values(5,'Rakesh',42,'Mathematics','2007-09-
05',25000,'M');
mysql> insert into teacher values(6,'Shyam',50,'History','2008-06-

27',30000,'M');
mysql> insert into teacher values(7,'Shiv Om',44,'Computer Sc','2017-
02-25',21000,'M');
mysql> insert into teacher values(8,'Shalakha',33,'Mathematics','2018-
07-31',20000,'F');

mysql> create table posting(P_ID int,Department


varchar(20),Place varchar(15));
mysql> insert into posting values(1,'History','Agra');
mysql> insert into posting values(2,'Mathematics','Raipur');
mysql> insert into posting values(3,'Computer Science','Delhi');
SQL queries:
1) Write SQL query to change datatype of Place to varchar(20).
2) Write SQL query to add new column state to table posting.

3) Write SQL query to change the name of column


Date_of_Join to DOJ in table teacher.

4) Write SQL query to increase salary of all teachers by 1000.


5) Write SQL query to delete column state from table posting.

6) Write SQL query to show all the information of history teachers.

7) Write SQL query to list the names of female teachers


who are Mathematics department.

8) Write SQL query to show the names of all teachers with


their date of joining in ascending order.
9) Write SQL query to display name, age, salary of all male teachers.

10) Write a query to display name, bonus for each teacher


where bonus is 10% of salary.

11) Write SQL query to count number of teacher in each department.


12) Write SQL query to display maximum and minimum date
of joining.

13) Write SQL query to display name, department of


all teachers whose place of posting is “Raipur”.

14) Write SQL query to display average salary of


Computer Science department teachers.

15) Write SQL query to display name, department and salary


of all teachers working in Agra.
16) Display details of all teachers in ascending order of their salary
and descending order of their age.

17) Display details of employees whose name start with ‘S’ and
ends with ‘a’

18) Write SQL query to display total salary drawn


by mathematics teachers.
Practical 17-Write a program to connect with database, create table
student, store records of students and display records.
Solution:
Output:
Program 18: Integrate MySQL with Python by importing the MySQL
module to search student using rollno, name, age, class and if present in
table display the record, if not display appropriate method.

Ans:

import os
import platform
import mysql.connector

mydb=mysql.connector.connect(host="localhost",\
user="root",\
passwd="root",\
database="student",charset="utf8")
print(mydb)
mycursor=mydb.cursor()

def stuview():
print("Select the search criteria : ")
print("1. Roll")
print("2. Name")
print("3. Age")
print("4. Class")
print("5. All")
ch=int(input("Enter the choice : "))
if ch==1:
s=int(input("Enter roll no : "))
rl=(s,)
sql="select * from stud where roll=%s"
mycursor.execute(sql,rl)
elif ch==2:
s=input("Enter Name : ")
rl=(s,)
sql="select * from stud where name=%s"
mycursor.execute(sql,rl)
elif ch==3:
s=int(input("Enter age : "))
rl=(s,)
sql="select * from stud where age=%s"
mycursor.execute(sql,rl)
elif ch==4:
s=input("Enter Class : ")
rl=(s,)
sql="select * from stud where clas=%s"
mycursor.execute(sql,rl)
elif ch==5:
sql="select * from stud"
mycursor.execute(sql)
res=mycursor.fetchall()
print("The Students details are as follows : ")
print("(ROll, Name, Age, Class)")
for x in res:
print(x)

def MenuSet(): #Function For The Student Management System


print("Enter 1 : To Search Student")
userInput = int(input("Please Select An Above Option: ")) #Will Take
Input From User
if(userInput == 1):
stuview()
MenuSet()
def runAgain():
runAgn = input("\nwant To Run Again Y/n: ")
while(runAgn.lower() == 'y'):
if(platform.system() == "Windows"):
print(os.system('cls'))
else:
print(os.system('clear'))
MenuSet()
runAgn = input("\nwant To Run Again y/n: ")

runAgain()
Output is:

<mysql.connector.connection.MySQLConnection object at 0x022720F0>


Enter 1 : To Search Student
Please Select An Above Option: 1
Select the search criteria :
1. Roll
2. Name
3. Age
4. Class
5. All
Enter the choice : 1
Enter roll no : 8
The Students details are as follows :
(ROll, Name, Age, Class)
(8, 'OM', 16, 12)

want To Run Again Y/n: y


0
Enter 1 : To Search Student
Please Select An Above Option: 1
Select the search criteria :
1. Roll
2. Name
3. Age
4. Class
5. All
Enter the choice : 2
Enter Name : MALINI
The Students details are as follows :
(ROll, Name, Age, Class)
(10, 'MALINI', 17, 12)

want To Run Again y/n: Y


0
Enter 1 : To Search Student
Please Select An Above Option: 1
Select the search criteria :
1. Roll
2. Name
3. Age
4. Class
5. All
Enter the choice : 3
Enter age : 15
The Students details are as follows :
(ROll, Name, Age, Class)
(4, 'SANGEETA', 15, 10)
(5, 'SANGEETA SETH', 15, 10)
(7, 'ANJU', 15, 10)

want To Run Again y/n: Y


0
Enter 1 : To Search Student
Please Select An Above Option: 1
Select the search criteria :
1. Roll
2. Name
3. Age
4. Class
5. All
Enter the choice : 4
Enter Class : 12
The Students details are as follows :
(ROll, Name, Age, Class)
(1, 'ANJU JHA', 17, 12)
(3, 'ANIKET JAISWAR', 16, 12)
(8, 'OM', 16, 12)
(10, 'MALINI', 17, 12)

want To Run Again y/n: Y


0
Enter 1 : To Search Student
Please Select An Above Option: 1
Select the search criteria :
1. Roll
2. Name
3. Age
4. Class
5. All
Enter the choice : 5
The Students details are as follows :
(ROll, Name, Age, Class)
(1, 'ANJU JHA', 17, 12)
(2, 'YASH', 16, 11)
(3, 'ANIKET JAISWAR', 16, 12)
(4, 'SANGEETA', 15, 10)
(5, 'SANGEETA SETH', 15, 10)
(6, 'YAMINI', 16, 11)
(7, 'ANJU', 15, 10)
(8, 'OM', 16, 12)
(9, 'MANGALA', 16, 11)
(10, 'MALINI', 17, 12)

want To Run Again y/n: N


>>>
Program 19-Write a program to connect with database and update and
delete the record from database. (Database:s1,table:teacher)
Solution:
Output:
Assignment 10: SQL QUERIES

Queries Set 1 (Database Fetching records)


[1] Consider the following MOVIE table and write the SQL queries based on it.

1. Display all information from the movie.


2. Display the type of movies.
3. Display movieid, movie name, total_eraning by showing the business done by
the movies. Calculate the business done by movie using the sum of production
cost and business cost.
4. Display movie id, movie name and production cost for all movies with production
cost greater than 150000 and less than 1000000.
5. Display the movie of type action and romance.
6. Display the list of movies which are going to release in February, 2022.

Answers:
[1] select * from movie ;
Output:

2. select distinct from a movie ;

3. select movieid, movie name, production cost + business cost “total earning” from
movie ;
4. select movie_id, movie name, production cost from movie where product is >150000
and <1000000 ;

5. select movie name from movie where type =’action’ or type=’romance’ ;

6. select movie name from movie where month(release date)=2 ;

Queries Set 2 (Based on Functions)

1. Write a query to display a cube of 5.


2. Write a query to display the number 563.854741 rounding off to the next
hundred.
3. Write a query to display “put” from the word “Computer”.
4. Write a query to display today’s date into DD.MM.YYYY format.
5. Write a query to display ‘DIA’ from the word “MEDIA”.
6. Write a query to display movie name – type from the table movie.
7. Write a query to display the first four digits of production cost.
8. Write a query to display the last four digits of business cost.
9. Write a query to display weekdays of release dates.
10. Write a query to display the dayname on which movies are going to be
released.

Answers:
[1] select pow(5,3) ;

[2] select round(563.854741,-2) ;

[3] select mid(“Computer”,4,3) ;


[4] select concat(day(now()),concat(‘.’,month(now()),concat(‘.’,year(now())))) “Date” ;

[5] select right(“Media”,3) ;

[6] select concat(movie name,concat(‘ – ‘,type)) from movie ;


[7] select left (production cost,4) from movie ;
[8] select right (business cost,4) from movie ;

[9] select weekday (release date) from movie ;


[10] select dayname (release date) from movie ;

Queries Set 3 (DDL Commands)


Suppose your school management has decided to conduct cricket matches between
students of Class XI and Class XII. Students of each class are asked to join any one of
the four teams – Team Titan, Team Rockers, Team Magnet and Team Hurricane. During
summer vacations, various matches will be conducted between these teams. Help your
sports teacher to do the following:

1. Create a database “Sports”.


2. Create a table “TEAM” with following considerations:
o It should have a column TeamID for storing an integer value between 1
to 9, which refers to unique identification of a team.
o Each TeamID should have its associated name (TeamName), which
should be a string of length not less than 10 characters.
o Using table level constraint, make TeamID as the primary key.
o Show the structure of the table TEAM using a SQL statement.
o As per the preferences of the students four teams were formed as
given below. Insert these four rows in TEAM table:
▪ Row 1: (1, Tehlka)
▪ Row 2: (2, Toofan)
▪ Row 3: (3, Aandhi)
▪ Row 3: (4, Shailab)
o Show the contents of the table TEAM using a DML statement.
3. Now create another table MATCH_DETAILS and insert data as shown below.
Choose appropriate data types and constraints for each attribute.

MatchI MatchDat FirstTeamI SecondTeamI FirstTeamScor SecondTeamSco


D e D D e re

M1 2021/12/2 1 2 107 93
0

M2 2021/12/2 3 4 156 158


1

M3 2021/12/2 1 3 86 81
2

M4 2021/12/2 2 4 65 67
3

M5 2021/12/2 1 4 52 88
4

M6 2021/12/2 2 3 97 68
5

Answers:
[1] create database sports
[2] Creating table with the given specification

create table team


-> (teamid int(1),
-> teamname varchar(10), primary key(teamid));

Showing the structure of table using SQL statement:

desc team;

Inserting data:

mqsql> insert into team


-> values(1,'Tehlka');
Show the content of table – team:

select * from team;


Creating another table:

create table match_details


-> (matchid varchar(2) primary key,
-> matchdate date,
-> firstteamid int(1) references team(teamid),
-> secondteamid int(1) references team(teamid),
-> firstteamscore int(3),
-> secondteamscore int(3));

Queries set 4 (Based on Two Tables)

1. Display the matchid, teamid, team score who scored more than 70 in first inning
along with team name.
2. Display matchid, team name and second team score between 100 to 160.
3. Display matchid, team names along with matchdates.
4. Display unique team names
5. Display matchid and match date played by Anadhi and Shailab.
Answers:
[1] select match_details.matchid, match_details.firstteamid, team.team
name,match_details.firstteamscore from match_details, team where
match_details.firstteamid=team.teamid and
match_details.firstteamscore>70;

[2] select matchid, team name, second team score from match_details, team were
match_details.secondteamid=team.teamid and match_details.secondteamscore
between 100 and 160;

[3] select matchid,team name,first teamid,secondteamid,match date from


match_details, team were match_details.firstteamid=team.team id;
[4] select distinct(team name) from match_details, team were
match_details.firstteamid=team.team id;

[5] select matchid,matchdate from match_details, team were


match_details.firstteamid=team.teamid and team.team name in
(‘Aandhi’,’Shailab’);

Queries Set 5 (Group by , Order By)


Consider the following table stock table to answer the queries:

item no item dcode qty unit price stockdate

S005 Ballpen 102 100 10 2018/04/22

S003 Gel Pen 101 150 15 2018/03/18

S002 Pencil 102 125 5 2018/02/25

S006 Eraser 101 200 3 2018/01/12

S001 Sharpner 103 210 5 2018/06/11


S004 Compass 102 60 35 2018/05/10

S009 A4 Papers 102 160 5 2018/07/17

1. Display all the items in the ascending order of stockdate.


2. Display maximum price of items for each dealer individually as per dcode from
stock.
3. Display all the items in descending orders of item names.
4. Display average price of items for each dealer individually as per doce from
stock which average price is more than 5.
5. Display the sum of quantity for each dcode.

[1] select * from stock order by stockdale;

[2] select dcode,max(unit price) from stock group by code;


[3] select * from stock order by item desc;

[4] select dcode,avg(unit price) from stock group by dcode having avg(unit price)>5;

[5] select dcode,sum(qty) from stock group by dcode;

You might also like