0% found this document useful (0 votes)
106 views

Class 12 Practical Programs

The document is a certification document for practical work completed by a student during the 2022-2023 academic year at Alpha School. It includes the student's name, register number, signatures of the principal and teacher, and an index of experiments completed with dates, page numbers, and signatures. The document is 55 pages long and provides certification of practical work completed as part of a Computer Science course.

Uploaded by

Jeevan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views

Class 12 Practical Programs

The document is a certification document for practical work completed by a student during the 2022-2023 academic year at Alpha School. It includes the student's name, register number, signatures of the principal and teacher, and an index of experiments completed with dates, page numbers, and signatures. The document is 55 pages long and provides certification of practical work completed as part of a Computer Science course.

Uploaded by

Jeevan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Page 1 of 55

2023-2024

NAME:

REGISTER NUMBER:
Page 2 of 55

ALPHA SCHOOL
(AFFILIATED TO CBSE, NEW DELHI)

Certified Bonafide practical work of ………………………………………………………………

of Class XII in the Computer Science Department of Alpha School, Chennai during the

academic year 2023 – 2024.

…………………………………….. ….…………………………………

SIGNATURE OF THE PRINCIPAL SIGNATURE OF THE TEACHER

Register No. ……………………………………

Submitted for the practical Examination held on …………………………………….. at Alpha

School, Chennai.

INTERNAL EXAMINER:

EXTERNAL EXAMINER:
Page 3 of 55

INDEX

EXPT. DATE NAME OF THE EXPERIMENT PAGE SIGNATURE


NO. NO.
1 13.6.23 Function to find the factorial of natural number 5

2 20.6.23 Function to find the sum of all elements in a list 6

3 27.6.23 Function to find the nth term of Fibonacci series 7

Read a text file and display each word separated


4 4.7.23 8
by ‘#’
Read a text file and display number of vowels,
5 11.7.23 9
consonants, uppercase, lowercase characters
Create binary file with name and roll number
6 18.7.23 11
and search for given name and number
Create a binary file with roll number, name and
7 25.7.23 13
marks. Input roll number and update the marks

8 1.8.23 Remove all the lines that contains ‘a’ in a file 16

Create a CSV file with name and roll number.


9 8.8.23 18
Search for roll number and display name

Read a CSV file top5.csv and print them with


10 22.8.23 tab delimiter. 20
Ignore first row header to print in tabular form.
Program to count a total number of lines and
11 22.8.23 count the total number of lines starting with 'A', 22
'B', and 'C' from the file dfh.txt.
Program to know the cursor position and print the
text according to the below-given specifications:
Print the initial position
Move the cursor to 4th position
12 5.9.23 Display next 5 characters 24
Move the cursor to the next 10 characters
Print the current cursor position
Print next 10 characters from the current cursor
position
Program to store customer data into a binary file
cust.dat using a dictionary and print them on
13 5.9.23 26
screen after reading them. The customer data
contains ID as key, and name, city as values.
Program to implement a stack for the employee
14 12.9.23 details (empno, name). 28
Program to check whether a string is a
15 12.9.23 palindrome or not using stack. 31
Page 4 of 55

16 10.10.23 Queries Set 1 (Fetching records) 33

17 10.10.23 Queries Set 2 (Based on Aggregate Functions) 36

18 17.10.23 Queries Set 3 (DDL Commands) 38

19 17.10.23 Queries set 4 (Based on Two Tables) 41

20 31.10.23 Queries Set 5 (Group by , Order By) 44

7.11.23 SQL with Python record of employee and


21 47
display the record
14.11.23 SQL with Python to search employee using
22 49
employee number and display the record
21.11.23 SQL with Python to search a student using roll
23 51
number and update the record

SQL with Python to search a student using roll


24 28.11.23 54
number and delete the record
Page 5 of 55

PROGRAM – 1

FUNCTION TO FIND THE FACTORIAL OF NATURAL NUMBER


AIM:

To create a Python program with a user defined function to find the factorial of natural number

PROGRAM:

def factorial(n):
a=1
for i in range(1,n+1):
a=a*i
print("The factorial of ", n, "is " , a)
return
n = int(input( "Enter a number : "))
if n < 0:
print("Invalid! Enter a positive number")
elif n == 0:
print(" 1 ")
else:
factorial(n)

OUTPUT-1:

Enter a number : 5
The factorial of 5 is 120

OUTPUT-2:

Enter a number : -5
Invalid! Enter a positive number

RESULT:

The given program is successfully executed and the output is displayed and verified
Page 8 of 55

PROGRAM-4

READ A TEXT FILE AND DISPLAY EACH WORD SEPARATED BY ‘#’

AIM:

To read a text file and display each word separated by ‘#’

PROGRAM:

file = open("d:\program1.txt","r")
lines = file.readlines()
for line in lines:
words = line.split()
for word in words:
print(word+"#",end=' ')
print('')
file.close()

SAMPLE TEXT FILE: (program1.txt)

like a joy on the heart of a sorrow


the sunset hangs on a cloud
a gold storm of glittering sheaves

OUTPUT:

like# a# joy# on# the# heart# of# a# sorrow#


the# sunset# hangs# on# a# cloud#
a# gold# storm# of# glittering# sheaves#

RESULT:

The given program is successfully executed and the output is displayed and verified
Page 9 of 55

PROGRAM-5

READ A TEXT FILE AND DISPLAY NUMBER OF VOWELS, CONSONANTS, UPPERCASE,


LOWERCASE CHARACTERS

AIM:

To read a text file and display number of vowels, consonants, uppercase, lowercase characters

PROGRAM:

file=open("d:\program2.txt","r")
content = file.read()
vowels = consonants = lowercase = uppercase = 0
for ch in content:
if ch.islower():
lowercase += 1
elif ch.isupper():
uppercase += 1
ch = ch.lower()
if ch in ['a','e','i','o','u']:
vowels +=1
else:
consonants += 1
file.close()
print("\nNumber of uppercase characters : ",uppercase)
print("\n\nNumber of lowercase characters : ",lowercase)
print("\n\nNumber of vowels : ",vowels)
print("\n\nNumber of consonants : ",consonants)
Page 12 of 55

OUTPUT-1:

Enter the number of students : 3

Enter name : Aravind


Enter roll number : 12001
Enter name : Srivatsan
Enter roll number : 12002
Enter name : Srilaya
Enter roll number : 12003
Enter the roll number of the student : 12002

Student data found in the file


Name of the student = Srivatsan

OUTPUT-2:

Enter the number of students : 3

Enter name : Oviya


Enter roll number : 12004
Enter name : Srilaya
Enter roll number : 12005
Enter name : Judy
Enter roll number : 12006

Enter the roll number of the student : 12009


Student data not found in the file

GENERATED BINARY FILE: (program3.txt)

€•L ]”(}”(Œname”ŒOviya”Œroll_no”Mä.u}”(hŒSrilaya”hMå.u}”(hŒJudy”hMæ.ue.

RESULT:

The given program is successfully executed and the output is displayed and verified
Page 14 of 55

else:
print("The marks of the student was updated ")
file.close()
stud_data = {}
file = open("d:\program4.txt",'rb')
try:
while True:
stud_data = pickle.load(file)
print(stud_data)
except EOFError:
file.close()

GENERATED BINARY FILE:


program4.txt

€ •5 }”(Œname”ŒAbdullah”Œroll_no”Má.Œmarks”G@| u.€ •3
}”(Œname”ŒSujesh”Œroll_no”Mâ.Œmarks”G@~ u.€ •4
}”(Œname”ŒAravind”Œroll_no”Mã.Œmarks”G@y u.

OUTPUT-1:

Enter the number of students : 3


Enter name : Abdullah
Enter roll number : 12001
Enter the total marks : 450
Enter name : Sujesh
Enter roll number : 12002
Enter the total marks : 475
Enter name : Aravind
Enter roll number : 12003
Enter the total marks : 400

Enter the roll number of the student : 12002


Updated Mark : 490
The marks of the student was updated
{'name': 'Abdullah', 'roll_no': 12001, 'marks': 450.0}
{'name': 'Sujesh', 'roll_no': 12002, 'marks': 490.0}
{'name': 'Aravind', 'roll_no': 12003, 'marks': 400.0}
Page 18 of 55

PROGRAM-9

CREATE A CSV FILE WITH NAME AND ROLL NUMBER, SEARCH FOR ROLL NUMBER
AND DISPLAY NAME
AIM:

To create a CSV file with name and roll number, search for roll number and display name

PROGRAM:

import csv
f = open("d:\program9.csv")
csv_content = csv.reader(f)
csv_name = []
csv_rollno = []
for col in csv_content:
csv_name.append(col[0])
csv_rollno.append(col[1])
dict = { }
for rollno in csv_rollno:
for name in csv_name:
dict[rollno] = name
csv_name.remove(name)
break
i = input ("Enter the Roll Number : ")
if i in csv_rollno:
print("Name of the Student is ",dict[i])
else:
print("The entered Roll Number does not exist")
Page 19 of 55

SAMPLE CSV FILE:

Program9.csv

'name','roll number'
'Aravind','12001'
'Aakash','12002'
'Srivatsan','12003'
'Abrar','12004'
'Roshan','12005'

OUTPUT-1:

Enter the Roll Number : '12002'


Name of the Student is 'Aakash'

OUTPUT-2:

Enter the Roll Number : '12010'


The entered Roll Number does not exist

RESULT:

The given program is successfully executed and the output is displayed and verified
Page 23 of 55

File Contents: MyFile.txt

Python is super and trending language. Allows to store the output in the
files. A text file stores textual data.

Binary files can handle binary data.

Binary files use pickle module to store data. CSV files can handle tabular data.

CSV files can be read easily using CSV reader object.

OUTPUT:
Total Number of lines are: 8
Total Number of lines starting with A are: 2
Total Number of lines starting with B are: 2
Total Number of lines starting with C are: 2

RESULT:

The given program is successfully executed and the output is displayed and verified
Page 24 of 55

PROGRAM-12
TO FIND THE CURSOR POSITION AND PRINT THE TEXT
ACCORDING TO THE GIVEN SPECIFICATIONS
AIM:
To create a program to know the cursor position and print the text according to the below-given
specifications:
 Print the initial position
 Move the cursor to 4th position
 Display next 5 characters
 Move the cursor to the next 10 characters
 Print the current cursor position
 Print next 10 characters from the current cursor position

PROGRAM:

def program7():
f = open("G:\MyFile.txt","r")
print("Cursor initial position.")
print(f.tell())
f.seek(4,0)
print("Displaying values from 5th position.")
print(f.read(5))
f.seek(10,0)
print(f.tell())
print("Print cursor's current position")
print(f.seek(7,0))
print("Displaying next 10 characters from cursor's current position.")
print(f.read(10))
program7()
Page 25 of 55

SAMPLE TEXT FILE: myfile.txt


Python is super and trending language. Allows to store the output in the
files. A text file stores textual data.

Binary files can handle binary data.

Binary files use pickle module to store data. CSV files can handle tabular data.

CSV files can be read easily using CSV reader object.

OUTPUT:
Cursor initial position.
0
Displaying values from 5th position.
on is
10
Print cursor's current position
7
Displaying next 10 characters from cursor's current position.
is super a

RESULT:

The given program is successfully executed and the output is displayed and verified
Page 28 of 55

PROGRAM 14

PROGRAM TO IMPLEMENT A STACK FOR THE EMPLOYEE DETAILS

AIM:
To write a program to implement a stack for the employee details (empno, name).
PROGRAM:
stk=[]
top=-1
def line():
print('~'*80)
def isEmpty():
global stk
if stk==[]:
print("Stack is empty!!!")
else:
None
def push():
global stk
global top
empno=int(input("Enter the employee number to push:"))
ename=input("Enter the employee name to push:")
stk.append([empno,ename])
top=len(stk)-1
def display():
global stk
global top
if top==-1:
isEmpty()
else:
top=len(stk)-1
print(stk[top],"<-top")
for i in range(top-1,-1,-1):
print(stk[i])
def pop_ele():
global stk
global top
Page 29 of 55

if top==-1:
isEmpty()
else:
stk.pop()
top=top-1
def main():
while True:
line()
print("1. Push")
print("2. Pop")
print("3. Display")
print("4. Exit")
ch=int(input("Enter your choice:"))
if ch==1:
push()
print("Element Pushed")
elif ch==2:
pop_ele()
elif ch==3:
display()
elif ch==4:
break
else:
print("Invalid Choice")
main()
Page 32 of 55

if isPalindrome(string):
print("Yes, the string is a palindrome")
else:
print("No, the string is not a palindrome")

OUTPUT:

Enter string to check: malayalam


Yes, the string is a palindrome

Enter string to check: program


No, the string is not a palindrome

RESULT:

The given program is successfully executed and the output is displayed and verified
Page 33 of 55

PROGRAM 16
QUERIES SET 1 (FETCHING RECORDS)

AIM:
To write a set of Queries for fetching records from the table.

Consider the following MOVIE table and write the SQL queries based on it.
Movie_ID MovieName Type ReleaseDate ProductionCost BusinessCost
M001 Dahek Action 2022/01/26 1245000 1300000
M002 Attack Action 2022/01/28 1120000 1250000
M003 Looop Lapeta Thriller 2022/02/01 250000 300000
M004 Badhai Do Drama 2022/02/04 720000 68000
M005 Shabaash Mithu Biography 2022/02/04 1000000 800000
M006 Gehraiyaan Romance 2022/02/11 150000 120000
a) Display all information from movie.
b) Display the type of movies.
c) Display movieid, moviename, total_eraning by showing the business done by the
movies. Claculate the business done by movie using the sum of productioncost and
businesscost.
d) Display movieid, moviename and productioncost for all movies with
productioncost greater thatn 150000 and less than 1000000.
e) Display the movie of type action and romance.
f) Display the list of movies which are going to release in February, 2022.

Answers:
a) SELECT * FROM movie;
Page 35 of 55

e) SELECT moviename FROM movie WHERE type = ‘action’ OR type = ‘romantic’;

f) SELECT moviename FROM movie WHERE MONTH(releasedate) = 2;

Result:
Thus the queries are written and executed successfully.
Page 38 of 55

PROGRAM 18
QUERIES SET 3 (DDL COMMANDS)

AIM:
To write a set of DDL Commands for the following question.

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
a) Create a database “Sports”.
b) Create a table “TEAM” with following specifications:
a. It should have a column TeamID for storing an integer value between 1 to 9,
which refers to unique identification of a team.
b. Each TeamID should have its associated name (TeamName), which should be a
string of length not less than 10 characters.
c. Using table level constraint, make TeamID as the primary key.
c) Show the structure of the table TEAM using a SQL statement.
d) As per the preferences of the students four teams were formed as given below. Insert
these four rows in TEAM table:
a. Row 1: (1, Tehlka)
b. Row 2: (2, Toofan)
c. Row 3: (3, Aandhi)
d. Row 3: (4, Shailab)
e) Show the contents of the table TEAM using a DML statement.
f) Now create another table MATCH_DETAILS and insert data as shown below. Choose
appropriate data types and constraints for each attribute.
MatchID MatchDate FirstTeamID SecondTeamID FirstTeamScore SecondTeamScore
M1 2021/12/20 1 2 107 93
M2 2021/12/21 3 4 156 158
M3 2021/12/22 1 3 86 81
M4 2021/12/23 2 4 65 67
M5 2021/12/24 1 4 52 88
M6 2021/12/25 2 3 97 68
Page 39 of 55

Answers:
a) CREATE DATABASE sports;

b) Creating table with the given specification:


CREATE TABLE TEAM (teamid int(1),teamname varchar(10), primary key(teamid));

c) DESC TEAM;

d) Inserting Data:

e) Show the contents of the table TEAM;


Page 40 of 55

f) Creating another table

Result:
Thus the queries are written and executed successfully.
Page 44 of 55

PROGRAM 20
QUERIES SET 4 (GROUP BY, ORDER BY)

AIM:
To write a set of Queries based on GROUP BY and ORDER BY for the following questions.
TABLE : STOCK
itemno Item dcode qty unitprice 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

a) Display all the items in the ascending order of stockdate.


b) Display maximum price of items for each dealer individually as per dcode from stock.
c) Display all the items in descending orders of itemnames.
d) Display average price of items for each dealer individually as per doce from
stock which average price is more than 5.
e) Display the sum of quantity for each dcode.
ANSWERS:
a) SELECT * FROM stock ORDER BY stockdate;
Page 45 of 55

b) SELECT dcode,MAX(unitprice) FROM stock GROUP BY code;

c) SELECT * FROM stock ORDER BY item DESC;

d) SELECT dcode,AVG(unitprice) FROM stock GROUP BY dcode


HAVING AVG(unitprice)>5;
Page 46 of 55

e) SELECT dcode,SUM(qty) FROM stock GROUP BY dcode;

Result:
Thus the queries are written and executed successfully.
Page 50 of 55

MYSQL – DATABASE : employee

OUTPUT-1:

Enter the employee's name : Srivatsan


--- Employee Details ---
(12002, 'Srivatsan', 'Sales Manager')

OUTPUT-1:

Enter the employee's name : Sundar


Employee not in database

RESULT:

The given program is successfully executed and the output is displayed and verified
Page 51 of 55

PROGRAM – 23

SQL WITH PYTHON TO SEARCH A STUDENT USING ROLL NUMBER AND


UPDATE THE RECORD

AIM:

To create a Python program to search for a student record using roll number from MySQL database
and update the record.

PROGRAM:

import mysql.connector as sql1


mycon = sql1.connect(host = 'localhost', user ='root', passwd = '', database = 'student')
cursor = mycon.cursor()
cursor.execute('SELECT * FROM student')
b = []
x = cursor.fetchall()
print(" --- Update Student Marks ---")
rollno = int(input("Enter the Roll Number : " ))
for row in x:
b.append(row)
for a in range(len(b)):
if b[a][0] == rollno:
updated_marks = int(input("Enter the Updated Marks : "))
ud = "UPDATE student SET marks = {} WHERE roll_no = {}".format(updated_marks ,rollno)
cursor.execute(ud)
print(" The marks have been successfully updated ")
break
else:
print("The student was not found in the database ")
Page 52 of 55

MYSQL – DATABASE :

student-before updating the record

student-after updating the record


Page 55 of 55

MYSQL – DATABASE :

Student - before updating the record

Student - after updating the record

OUTPUT:

--- Delete Student Record ---


Enter the Roll Number: 12002
The student's record has been deleted

RESULT:

The given program is successfully executed and the output is displayed and verified

You might also like