Nalin FINAL JAN 17 Tgjy 3 2
Nalin FINAL JAN 17 Tgjy 3 2
OOTY
PRACTICAL FILE
2024-2025
COMPUTER SCIENCE
~ Nalin Manickam
CLASS XII A
CERTIFICATE
___________________________
INTERNAL’S SIGNATURE
___________________________
EXTERNAL’S SIGNATURE
___________________________
PRINCIPAL’S SIGNATURE
ACKNOWLEDGEMENT
2. LIBRARY FUNCTIONS
MySQL
3. CREATING MODULES AND PACKAGES
1. CREATING TABLES AND INSERTING RECORD
4. SIMULATING A DICE RANDOMLY
5.
2. WRITING
TO ADD ANDAND
COLUMNS READING DATA
UPDATE TABLE
4.
7. EXTRACTING
TO READ A TEXT FILE USING DATA
BUILT IN FUNCTIONS
5. USING FUNCTIONS
8. FIND THE MOST COMMONLY OCCURING WORD IN A TEXT FILE
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")
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()
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()
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)")
import csv
f=open("emp.csv","w")
empwriter=csv.writer(f)
empwriter.writerow(['empno', 'name', 'designation', 'salary'])
for i in range(3):
print("Employee record",i+1)
empno=int(input("Enter empno:"))
name=input("Enter name:")
designation=input("Enter the designation:")
salary=int(input("Enter salary:"))
emprec=[empno,name,designation,salary]
empwriter.writerow(emprec)
f.close()
def f_csvwrite():
f=open("goods.csv","w")
dt=writer(f)
dt.writerow(['code', 'description','price'])
|=[]
choice="y"
while choice=="y":
r=input("Enter code:")
b=input("Enter description:")
s=input("Enter price:")
l=[r,b,s]
dt.writerow(1)
choice=input("Enter y to continue:")
f.close()
f_csvwrite()
PROGRAM-17 STACKS
AIM: To create a stack
stk=[]
def display():
if stk==[]:
print("Stack empty")
else:
for x in range(len(stk)):
print(stk[x])
def push():
e_no=int(input("Enter employee number:"))
e_name=input("Enter employee name:")
e_sal=int(input("Enter employee salary:"))
l=[e_no,e_name,e_sal]
stk.append(l)
def pop():
if stk==[]:
print("Stack empty")
else:
item=stk.pop(-1)
print("Deleted element is:",item)
def peek():
if stk==[]:
print("Stack empty")
else:
item=stk[-1]
print("Peeked element :",item)
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
MySQL
1. Create table department based on the following instance and populate the table.
2. Create table staff based on the following instance and populate the table.
Column Data type Constraints
S_no Integer Primary key
S_name Varchar(30) Not null
Salary Float N/A
Zone Varchar(15) N/A
Age Int Greater than 20
Grade Char(1) N/A
Dept Int Foreign key
(Dept table)
OUTPUT
Source code :
OUTPUT :
Source code :
OUTPUT :
SOURCE CODE:
OUTPUT:
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:
OUTPUT:
SOURCE CODE:
OUTPUT:
Practical 5 : Using Functions
1. Display maximum salary and minimum salary from table
employee under appropriate column headings
Practical-6:
1. Display d_name of table department in uppercase
SOURCE CODE :
INSERTING VALUES :
Describe table :
Using function(lower()) :
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
Create Table
Inserting Values :
Display employees details as name , Salary, Zone, Grade only
for east zone by comparing Isal and Hsal
CARTESIAN PRODUCT :
NATURAL JOIN :
Natural join is to avoid identical columns being replicated
(no on clause required )
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 :
Practical-4 Searching data from a sql table
Source code:
Output:
Practical -5 Deleting data from sql table:
Source code:
Output: