Class 12 Practical Programs
Class 12 Practical Programs
2023-2024
NAME:
REGISTER NUMBER:
Page 2 of 55
ALPHA SCHOOL
(AFFILIATED TO CBSE, NEW DELHI)
of Class XII in the Computer Science Department of Alpha School, Chennai during the
…………………………………….. ….…………………………………
School, Chennai.
INTERNAL EXAMINER:
EXTERNAL EXAMINER:
Page 3 of 55
INDEX
PROGRAM – 1
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
AIM:
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()
OUTPUT:
RESULT:
The given program is successfully executed and the output is displayed and verified
Page 9 of 55
PROGRAM-5
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:
OUTPUT-2:
€•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()
€ •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:
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
Program9.csv
'name','roll number'
'Aravind','12001'
'Aakash','12002'
'Srivatsan','12003'
'Abrar','12004'
'Roshan','12005'
OUTPUT-1:
OUTPUT-2:
RESULT:
The given program is successfully executed and the output is displayed and verified
Page 23 of 55
Python is super and trending language. Allows to store the output in the
files. A text file stores textual data.
Binary files use pickle module to store data. CSV files can handle tabular data.
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
Binary files use pickle module to store data. CSV files can handle tabular data.
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
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:
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
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;
c) DESC TEAM;
d) Inserting Data:
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
Result:
Thus the queries are written and executed successfully.
Page 50 of 55
OUTPUT-1:
OUTPUT-1:
RESULT:
The given program is successfully executed and the output is displayed and verified
Page 51 of 55
PROGRAM – 23
AIM:
To create a Python program to search for a student record using roll number from MySQL database
and update the record.
PROGRAM:
MYSQL – DATABASE :
MYSQL – DATABASE :
OUTPUT:
RESULT:
The given program is successfully executed and the output is displayed and verified