FATHER AGNEL SCHOOL ,NOIDA
Computer science
Practical file
(2024-25)
Name : Lokesh Singh
Class: 12
Section: A
Board Roll no.:
This is to certify that LOKESH SINGH, student of class XII
of Father Agnel School Noida has completed his practical
file work in the year 2024- 25. He has taken proper care
and utmost sincerity in completion of this project.
I certify that this project is up to my expectations and as
per the latest guidelines issued by CBSE.
Amit Sethi
C.S. teacher
PYTHON PROGRAMMES
1)Write a program to display ASCII code of a character and vice versa.
Output:
Press-1 to find the ordinal value of a character
Press-2 to find a character of a value
Enter a character: a
97
Do you want to continue? Y/N
Press-1 to find the ordinal value of a character
Press-2 to find a character of a value
Enter an integer value: 65
Do you want to continue? Y/N
2) Write a program to read a text file line by line and display each word separated by '#'.
Text in file:
hello how are you?
python is case-sensitive language.
Output in python shell:
hello#how#are#you?#python#is#case-sensitive#language.#
3) Write a program to count the number of vowels present in a text file.
Output:
4) Write a program to check a number whether it is palindrome or not.
Output:
Enter a number :6556
Number is Palindrome
5) Write a program to search a record using its roll number and display the name of student. If record not
found then display appropriate message.
import pickle
roll = input('Enter roll number that you want to search in binary file :')
file = open("student.dat", "rb")
Output:
Enter roll number that you want to search in binary file :1202
Name of student is: Divya
6) Write a program to generate random numbers between 1 to 6 and check whether a user won a lottery or
not.
Output:
Enter a number between 1 to 6 : 4
Sorry, Try again, The lucky number was : 1
7) Write a program to count the number of times the occurrence of 'is' word in a text file.
Output:
8) Write a program to write those lines which have the character 'p' from one text file to another text file.
Output:
**Write contents of book.txt and story.txt
9) Create a binary file with name and roll number of student and display the data by reading the file.
Output:
Press-1 to write data and Press-2 to read data
Enter student Roll No:1201
Enter student Name :Devansh
Want to add more record(y/n) :y
Enter student Roll No:1202
Enter student Name :Divya
Want to add more record(y/n) :n
Press-1 to write data and Press-2 to read data 2
[{'roll': '1201', 'name': 'Devansh'}, {'roll': '1202', 'name': 'Divya'}]
10) Write a program to update the name of student by using its roll number in a binary file.
Output:
Enter roll number whose name you want to update in binary file :1202
Enter new name: Harish Record
Updated
11) Program to store student’s details like admission number, roll number, name and percentage in a dictionary
and display information on the basis of admission number.
Output:
12) Program to read the content of file and display the total number of consonants, uppercase, vowels and
lower case characters.
Output:
13) Write a program for linear search.
Output:
Enter the elements: 23,67,44,99,65,33,78,12
Enter the element that you want to search : 33
Element found at the position : 6
14) Write a program to delete a record from binary file.
Output:
Enter roll number whose record you want to delete:1201
Record Deleted
15) Write a program for bubble sort.
Output:
Enter the elements:[67,13,89,34,65,8,74,19]
The sorted list is : [8, 13, 19, 34, 65, 67, 74, 89]
MYSQL QUERIES
1) To write SQL-queries for the following questions based on the given table:
(f) Write a Query to insert all the rows of above table into Info table.
Sol: INSERT INTO STU VALUES (1,'Arun','M', 24,'COMPUTER','1997-01-10', 120);
INSERT INTO STU VALUES (2,'Ankit','M', 21,'HISTORY','1998-03-24', 200);
INSERT INTO STU VALUES (3,'Anu','F', 20,'HINDI','1996-12-12', 300);
INSERT INTO STU VALUES (4,'Bala','M', 19, NULL,'1999-07-01', 400);
INSERT INTO STU VALUES (5,'Charan','M', 18,'HINDI','1997-06-27', 250);
INSERT INTO STU VALUES (6,'Deepa','F', 19,'HISTORY','1997-06-27', 300);
INSERT INTO STU VALUES (7,'Dinesh','M', 22,'COMPUTER','1997-02-25', 210);
INSERT INTO STU VALUES (8,'Usha','F', 23, NULL,'1997-07-31', 200);
2) To write SQL-queries for the following questions based on the given two table :
3) Queries for Aggregate functions- SUM( ), AVG( ), MIN( ), MAX( ), COUNT( )
a. Find the average salary of the employees in employee table.
Solution:- SELECT avg(salary) FROM EMPLOYEE;
b. Find the minimum salary of a female employee in EMPLOYEE table.
Solution:- SELECT Ename, min(salary) FROM EMPLOYEE WHERE sex=’F’;
c. Find the maximum salary of a male employee in EMPLOYEE table.
Solution:- SELECT Ename, max(salary) FROM EMPLOYEE WHERE sex=’M’;
d. Find the total salary of those employees who work in Guwahati city.
Solution:- SELECT sum(salary) FROM EMPLOYEE WHERE city=’Guwahati’;
4) Create a table EMPLOYEE with constraints
5) Write SQL queries using SELECT, FROM, WHERE clause based on EMPLOYEE table.
1. List the name of female employees in EMPLOYEE table.
Solution:- SELECT Ename FROM EMPLOYEE WHERE sex=’F’;
2. Display the name and department of those employees who work in surat and salary is greater than 25000.
Solution:- SELECT Ename, Dept FROM EMPLOYEE WHERE city=’surat’ and salary > 25000;
3. Display the name of those female employees who work in Mumbai.
Solution:- SELECT Ename FROM EMPLOYEE WHERE sex=’F’ and city=’Mumbai’;
4. Display the name of those employees whose department is marketing or RND.
Solution:- SELECT Ename FROM EMPLOYEE WHERE Dept=’marketing’ OR Dept=’RND’;
6) Queries using DISTINCT, BETWEEN, IN, LIKE, IS NULL, ORDER BY, GROUP BY, HAVING
A. Display the name of departments. Each department should be displayed once.
SOLUTION: SELECT DISTINCT(Dept) FROM EMPLOYEE;
B. Find the name and salary of those employees whose salary is between 35000 and 40000.
SOLUTION: SELECT Ename, salary FROM EMPLOYEE WHERE salary BETWEEN 35000 and 40000;
C. Find the name of those employees who live in guwahati, surat or jaipur city.
SOLUTION: SELECT Ename, city FROM EMPLOYEE WHERE city IN(‘Guwahati’,’Surat’,’Jaipur’);
D. Display the name of those employees whose name starts with ‘M’.
SOLUTION: SELECT Ename FROM EMPLOYEE WHERE Ename LIKE ‘M%’;
PYTHON CONNECTIVITY WITH MYSQL
1) Program to connect with database and store record of employee and display records
import mysql.connector as mycon
con = mycon.connect(host='localhost', user='root', password="root")
Output:
2) Program to connect with database and search employee number in table employee and display record, if
empno not found display appropriate message.
import mysql.connector as mycon
con = mycon.connect(host='localhost', user='root', password="root", database="company")
Output:
3) Perform all the operations (Insert, Update, Delete, Display) with reference to table ‘student’ throughMySQL-
Python connectivity
import mysql.connector as ms
db=ms.connect(host="localhost", user="root", passwd="root", database="class_xii" )
db = ms.connect( host="localhost", user="root", passwd="root", database="class_xii" )
Output:
4) Write a Menu Based Python databaseconnectivity script that performs thefollowing operations on the
tablenamed PRODUCT in SHOP Database.Observe the data given and setsuitable primary key for the table
and appropriate datatypes for the fields.
Output: