Nalin PRACTICAL PRINT 2025
Nalin PRACTICAL PRINT 2025
OOTY
PRACTICAL FILE
2024-2025
COMPUTER SCIENCE
~ Nalin Manickam
CLASS XII A
CERTIFICATE
___________________________
INTERNAL’S SIGNATURE
___________________________
EXTERNAL’S SIGNATURE
___________________________
PRINCIPAL’S SIGNATURE
ACKNOWLEDGEMENT
PYTHON
1. THE AREA OF VARIOUS SHAPES
2. LIBRARY FUNCTIONS
MySQL
4. EXTRACTING DATA
5. USING FUNCTIONS
7. GROUPING DATA
8. SORTING DATA
9. INTERFACE PYTHON
PYTHON
PROGRAM-1 TO CALCULATE THE AREA OF VARIOUS SHAPES USING
FUNCTIONS
AIM: To easily calculate the area of different shapes and to reduce the program size
and calculations by using functions
def rectangle(x,y):
area=x"y
return area
def square(x):
area=x**2
return area
def circle(x):
area=3.14*x*x
return area
def triangle(x,y):
area=0.5*x*y
return area
y="yes"
while y=="yes":
print("MENU")
print("Which area do you want to find?")
print("1.Area of triangle")
print("2.Area of rectangle")
print("3.Area of square")
print("4.Area of circle")
x=int(input("enter your choice:"))
if x==1:
base=int(input("enter base of the triangle:"))
height=int(input("enter height of the triangle:"))
a=triangle(base,height)
print(a)
elif x==2:
l=int(input("enter length of the rectangle:"))
b=int(input("enter the breadth of the rectangle"))
a=rectangle(l,b)
print(a)
elif x==3:
s=int(input("enter the side of the square:"))
a=square(s)
print(a)
elif x==4:
r=int(input("enter the radius of the circle:"))
a=circle(r)
print(a)
y=input("do you want to continue? reply with yes/no")
OUTPUT:
import math
import string
y="yes"
while y=="yes":
print("MENU")
print("1.F 1.Functions in math module")
print("2.Functions in string module")
a=int(input("enter choice 1 or 2:"))
if a==1:
print("Choose the functions:")
print("1.sqrt")
print("2.exp")
print("3.pow")
print("4.sin")
print("5.cos")
print("6.radians")
b=int(input("choose a function:"))
if b==1:
x=int(input("enter the value to be calculated:"))
y=math.sqrt(x)
print(y)
elif b==2:
x=int(input("enter the value to be calculated:"))
y=math.exp(x)
print(y)
elif b==3:
x=int(input("enter value to be calculated:"))
a=int(input("enter power:"))
y=math.pow(x,a)
print(y)
elif b==4:
x=int(input("enter the value to calculated:"))
y=math.sin(x)
print(y)
elif b==5:
x=int(input("enter the value to calculated:"))
y=math.cos(x)
print(y)
elif b==6:
x=int(input("enter the value to calculated:"))
y=math.radians(x)
print(y)
elif a==2:
print("choose the functions:")
print("1.lower")
print("2.upper")
print("3.title")
print("4.find")
print("5.replace")
b=int(input("choose a function:"))
if b==1:
x=input("Enter the string:")
print(x.lower())
elif b==2:
x=input("Enter the string:")
print(x.upper())
elif b==3:
x=input("Enter the string:")
print(x.title())
elif b==4:
x=input("Enter the string:")
print(x.find(y))
elif b==5:
x=input("Enter the string:")
y=input("Enter word to be replaced:")
z=input("enter the new word:")
print(x.replace(y,z))
y=input("do you want to continue? (yes or no)")
OUTPUT :
f1=open("story.txt","w")
a=int(input("enter the limit:"))
for i in range(a):
name=input("enter name:")
f1.write(name)
f1.write("\n")
f1.close()
f1=open("story.txt","r")
for i in f1.readlines():
print(i)
f1.close()
PROGRAM-6 REMOVE ALL THE LINES THAT CONTAIN A SPECIFIC
CHARACTER IN A FILE AND WRITE IT INTO ANOTHER FILE
AIM: To write all the lines which do not contain a specific character into a new
file
f1=open("p.txt","r")
f2=open("book.txt","w")
X=""
c=0
for x in f1.read():
if "w" not in x:
f2.write(x)
f1.close()
f2.close()
f2=open("book.txt","r")
for i in f2.readlines():
print(i)
f2.close()
PROGRAM-7 TO READ A TEXT FILE USING BUILT IN FUNCTIONS
AIM: To display all the uppercase, lowercase, vowels, consonants and
special characters in the text file.
f1=open("poem.txt","r")
uc=lc=sc=sp=vo=co=0
for i in f1.read():
if i.isalpha():
if i.isupper():
uc+=1
if i in ['a', 'e', 'i', 'o','u']:
vo+=1
else:
co+=1
elif i.islower():
lc+=1
if i in ['a','e','i', 'o','u']:
vo+=1
else:
co+=1
else:
sp+=1
print("number of uppercase characters:",uc)
print("number of lowercase characters:",lc)
print("number of special characters:",sp)
print("number of vowels:",vo)
print("number of consonants:",co)
f1.close()
PROGRAM-8 FIND THE MOST COMMONLY OCCURING WORD IN
A TEXT FILE
AIM: To find the most commonly occurring word in a text file and
listing the frequencies of words in a text file
f=open("poem.txt","r")
contents=f.read()
wordlist=contents.split()
wordfeq=[]
high=0
word=""
existing=[]
for i in wordlist:
count=wordlist.count(i)
if i not in existing:
wordfeq.append([i,count])
existing.append(i)
if count>high:
high=count
word=i
print("the word",word,"occurs maximum times", high,"times")
print("\nother words have frequencies:")
print(wordfeq)
import pickle
def read():
st={}
fin=open("bin.dat","rb")
try:
print("File bin.dat stores these records")
while True:
st=pickle.load(fin)
print(st)
except EOFError:
fin.close()
def display():
fin=open("bin.dat","rb")
found=False
a=int(input("Enter the record to be searched:"))
try:
print("Searching in file bin.dat")
while True:
st=pickle.load(fin)
if st['rno']==a:
print(st)
found=True
except EOFError:
if found==False:
print("No such records found in the file")
else:
print("search successfull")
fin.close()
ans="y"
while ans=="y":
print("MENU")
print("1.read and display the records")
print("2.search for records")
z=int(input("enter the function:"))
if z==1:
read()
if z==2:
display()
ans=input("Do you want to continue(y/n)")
PROGRAM-12 UPDATING DATA TO A BINARY FILE
AIM: To update the details of a student on a binary file using pickle.
import pickle
st={}
found=False
fin=open("bin.dat","rb+")
a=int(input("Enter roll no to be updated:"))
b=input("Enter the detail to be updated:")
try:
while True:
rpos=fin.tell()
st=pickle.load(fin)
if st["rno"]==a:
if b=="name":
c=input("Enter the new name:")
st[b]=c
found=True
elif b=="rno":
c=int(input("Enter the new rollno:"))
st[b]=c
found=True
elif b=="marks":
c=float(input("Enter the new marks:"))
st[b]=c
fin.seek(rpos)
pickle.dump(st,fin)
found=True
except EOFError:
if found==False:
print("sorry,no match found")
else:
print("record successfully updated")
fin.close()
fin=open("bin.dat","rb")
try:
while True:
st=pickle.load(fin)
print(st)
except EOFError:
fin.close()
print("STACK OPERATION")
print("1.Display")
print("2.Push")
print("3.Pop")
print("4.Peek")
ch="y"
while ch=="y":
choice=int(input("enter your choice(1 to 5):"))
if choice==1:
display()
elif choice==2:
push()
elif choice==3:
pop()
elif choice==4:
peek()
break
else:
print('invalid choice')
ch=input("Enter y to cont q to quit")
MySQL
Part-1 : Data management
1. Create table department based on the following instance and populate the table.
OUTPUT:
2. Create table staff based on the following instance and populate the table.
OUTPUT
Practical - 2 : To add columns and update table
OUTPUT
1. Delete all records from staff table belonging to south zone and having grade A
Source code :
OUTPUT :
Source code :
OUTPUT :
1. Display S_no, S_name, Salary and corresponding d_name of all employees whose
age is between 25 and 35 ( Both values inclusive )
SOURCE CODE:
OUTPUT:
2. Display d_name and correspoonding S_name from tables department and staff
SOURCE CODE:
OUTPUT:
3. Display S_name, Salary, Zone and income tax of all the staff with appropriate
column headings ( Income tax to be calculated as 30% of salary )
SOURCE CODE:
OUTPUT:
4. Display all details of staff of south zone whose salary is greater than 50000
SOURCE CODE:
OUTPUT:
5. Display S_name, age , grade of staff whose name starts with the character “J”
SOURCE CODE:
OUTPUT:
Practical-6:
2. Remove leading and trailing spaces from d_name field of department table
2. Display all the details of employees in ascending order of age from table employee.
3. Display all the details of employee in descending order of grade and then by
ascending order of age from table employee
4. Display name and age of employee in ascending order or names where age is
between 20 and 40
SOURCE CODE :
INSERTING VALUES :
Describe table :
Using function(max()) :
Using function(min()) :
Using function(round())
Using function(sqrt())
Using function(sum())
Using function(upper()) :
GROUP BY :
CONDITION BASED :
Practical 10 : JOINS
Non-equi joins : a non-equi join is a query that specifies some relationship other than
equality between the columns
Create Table
Inserting Values :
Display employees details as name , Salary, Zone, Grade only for east zone by
comparing Isal and Hsal
CARTESIAN PRODUCT :
Equi-join : The join in which the columns are compared for equality . All the columns
would appear in the table being joined are included even if identical.
NATURAL JOIN :
Natural join is to avoid identical columns being replicated (no on clause required )
Write query to print all the fields where salary is greater than 60000 and grade=B
The result of “using“ clause is natural join and non-equi join :
Inner join :
Left join :
Right join :
INTERFACE PYTHON
1. Using the concept of interface python create a menu driven program to create
table, insert records and fetch records in sql
SOURCE CODE:
OUTPUT :
2.updating
OUTPUT :
Source code:
Output:
Source code:
Output: