Labour India Gurukulam Public School (C.B.S.
E)
Marangattupilly P.O 686635
Affl.No: 930115
Ph: 04822-250366
ALL INDIA SENIOR SCHOOL CERTIFICATE
2024-2025
PRACTICAL RECORD BOOK
COMPUTER SCIENCE
Submitted by: _________________________
Reg:
LABOUR INDIA GURUKULAM PUBLIC SCHOOL
JUNIOR COLLEGE
MARANGATTUPILLY,KOTTAYAM, KERALA-686635
BONAFIDE CERTIFICATE
This is to certify that this is a bonafide practical record
carried out under our supervision and guidance of
…………………………………………. in the academic year 2024-
2025 by ……………………………………...............................
Of class ………….…… reg no.……………………….…. of this
school, which is submitted in partial fulfilment for A.I.S.S.C.E of
Central Board of Secondary Education.
Principal Teacher in Charge
Submitted for the examination held
on …………………………………………….
External Examiner Internal Examiner
2
INDEX
Sl. No Program Page No. Remarks
1 Pgm 1 : Biggest among three numbers 5
2 Pgm 2 : Print Table of nth number 6
3 Pgm 3 : Print factorial of a number 7
4 Pgm 4 : Print factorial using recursion 8
5 Pgm 5 : To check prime number 9
6 Pgm 6 : Find sum of elements of a list 10
7 Pgm 7 : Count of vowels in a string 12
8 Pgm 8 : Search in a string 13
9 Pgm 9 : Random number generator 14
10 Pgm 10 : Read text file and count words 15
11 Pgm 11 : Read text file and add # to each word 16
12 Pgm 12 : Create and update binary file 19
13 Pgm 13: Read text file and move words to another file 21
14 Pgm 14: Implement stack using list of numbers 23
15 Pgm 15: Implement stack using list of names 26
3
16 Pgm 16: Table creation using python and MySQL 28
17 Pgm 17: Inserting records into MySQL table 29
18 Pgm 18: Updating records in MySQL table. 31
19 Pgm 19: Deleting records from MySQL table. 32
20 Pgm 20: Fetching records from MySQL table -1 33
21 Pgm 21: Fetching records from MySQL table -2 35
22 Pgm 22: Joining two tables using python and MySQL 36
23 Pgm 23: MySQL commands – simple queries 38
24 Pgm 24: MySQL commands –selection queries 40
25 Pgm 25: MySQL commands – functions and grouping 42
4
Program number – 1 : Biggest among three numbers
Date : 12-07-2024
AIM : To write a python script to take input for 3 numbers, check and print the
largest number
Program :
a = int(input("Enter first number"))
b = int(input("Enter second number"))
c = int(input("Enter third number"))
if(a>b and a<c):
biggest = a
elif(b>c):
biggest = b
else:
biggest = c
print ("Biggest number is ",biggest)
Output :
5
Program number – 2 : Table of nth number
Date :12-07-2024
AIM : To write a python script to take input for a number and print its table
Program :
a = int(input("Enter the number"))
for i in range(1,11):
print (i, ‘X’, a,'=',i*a)
Output :
6
Program number – 3 : To print factorial
Date : 19-07-2024
AIM : To write a python script to take input for a number and print its factorial
Program :
a = int(input("Enter the number"))
fact = 1
for i in range(1,a+1):
fact = fact * i
print ("Factorial of ",a," is ",fact)
Output :
7
Program number – 4 : To check prime number
Date :19-07-2024
AIM : To input a number and check the number is prime or not
Program :
num = int(input("Enter the number "))
if num > 1:
for i in range(2, int(num/2)+1):
if (num % i) == 0:
print(num, "is not a prime number")
break
else:
print(num, "is a prime number")
else:
print(num, "is not a prime number")
Output :
8
Program number – 5 : Find sum of elements of a list
Date : 09-08-2024
AIM : To find the sum of elements of agiven list
Program :
list1 = [11, 5, 17, 18, 23]
total = 0
for ele in range(0, len(list1)):
total = total + list1[ele]
# printing total value
print("Sum of all elements in given list: ", total)
Output :
9
Program number – 6 : Count of vowels in a string
Date :09-08-2024
AIM : To find the total number of vowels in a given string
Program :
def vowel_count(str1):
count = 0
vowel = "aeiouAEIOU"
for alphabet in str1:
if alphabet in vowel:
count = count + 1
print("No. of vowels :", count)
str1 = input("Enter String ")
vowel_count(str1)
10
Output :
11
Program number – 7 : Search in a string
Date : 23-08-2024
AIM : To check a word is present in a string or not.
Program :
string1 = input("Enter sentense ")
string2 = input("Ener string to search")
words = string1.split()
if string2 in words:
print (string2, "is present in above sentense")
else:
print (string2, "is not present in above sentense")
Output :
12
Program number – 8 : Random number generator
Date : 23-08-2024
AIM : To write a program to generate a random number between 0 and 9
Program :
# importing the random module
import random
print(random.randint(0,9))
Output :
13
Program number – 9 : Read text file and count words
Date : 23-08-2024
AIM : To Read a text file and display the number of words in the file
Program :
file = open("data.txt", "r")
data = file.read()
words = data.split()
print('Number of words in text file :', len(words))
Output :
14
Program number – 10: Read text file and add # to each word
Date : 13-09-2024
AIM : To read a text file line by line and display each word separated by a #
Program :
filein = open("data.txt",'r')
for line in filein:
word= line .split()
for w in word:
print(w + '#',end ='')
print()
filein.close()
Output :
15
Program number – 11 : Create and update binary file
Date : 13-09-2024
AIM : To Create a binary file with roll number, name and marks. Input a roll number and
update the marks
Program :
import pickle
#creating the file and writing the data
f=open("records.dat", "wb")
#list index 0 = roll number
#list index 1 = name
#list index 2 = marks
pickle.dump([1, "Wakil", 90], f)
pickle.dump([2, "Tanish", 80], f)
pickle.dump([3, "Priyashi", 90], f)
pickle.dump([4, "Kanupriya", 80], f)
pickle.dump([5, "Ashutosh", 85], f)
f.close()
#opeining the file to read contents
f=open("records.dat", "rb")
roll=int(input("Enter the Roll Number: "))
marks=float(input("Enter the updated marks: "))
List = [ ] #empty list
flag = False #turns to True if record is found
while True:
try:
record=pickle.load(f)
16
List.append(record)
except EOFError:
break
f.close()
#reopening the file to update the marks
f=open("records.dat", "wb")
for rec in List:
if rec[0]==roll:
rec[2] = marks
pickle.dump(rec, f)
print("Record updated successfully")
flag = True
else:
pickle.dump(rec,f)
f.close()
if flag==False:
print("This roll number does not exist")
17
Output :
18
Program number – 12 : Read text file and move words to another file
Date : 13-09-2024
AIM : To Read a file remove all the lines that contain the character `a' in a file and write
it to another file.
Program :
myfile = open("data.txt", "r")
newfile = open("data_new.txt", "w")
line = " "
while line:
line = myfile.readline()
if 'a' not in line:
newfile.write(line)
myfile.close()
newfile.close()
print("Successfully created")
19
Output :
20
Program number – 13 : Insert data to binary file
Date : 04-10-2024
AIM : To write a Python program to write student data in binary file python.
Program :
import pickle
def write():
file = open("binary.dat","wb")
records = []
x =21
while(x == 21):
rno = int(input("Enter Roll number: "))
name = input("Enter Name: ")
grade = input("Enter Grade: ")
marks = int(input("Enter Marks: "))
data = [rno,name,grade,marks]
records.append(data)
ch = input("Do you want to ad more records: ")
if ch == 'n':
break
pickle.dump(records,file)
file.close()
write()
21
Output :
22
Program number – 14 : Implement Stack Using List of Numbers
Date : 04-10-2024
AIM : To write a python script to implement stack using list (Push & Pop
Operation) using numbers.
Program :
def isEmpty(s):
if len(s)==0:
return True
else:
return False
def push(s,item):
s.append(item)
top=len(s)-1
def pop(s):
if isEmpty(s):
return 'Underflow occurs'
else:
val=s.pop()
if len(s)==0:
top=None
else:
top=len(s)-1
return val
def show(s):
if isEmpty(s):
print('no item found')
else:
t=len(s)-1
print('(TOP)',end='')
while(t>=0):
print(s[t],'<==',end='')
t=t-1
print()
23
s=[]
top=None
while True:
print('****** STACK IMPLEMENTATION USING LIST ******')
print('1: Add Number')
print('2: Remove Number')
print('3: Show Stack')
print('0: Exit')
ch=int(input('Enter choice:'))
if ch==1:
val=int(input('Enter no to push:'))
push(s,val)
elif ch==2:
val=pop(s)
if val=='Underflow':
print('Stack is empty')
else:
print('\nDeleted item is:',val)
elif ch==3:
show(s)
elif ch==0:
print('Bye')
break
24
Output :
25
Program number – 15 : Implement Stack Using List of Names
Date : 04-10-2024
AIM : To write a python script to implement stack using list (Push & Pop
Operation) using numbers.
Program :
def isEmpty(s):
if len(s)==0:
return True
else:
return False
def push(s,item):
s.append(item)
top=len(s)-1
def pop(s):
if isEmpty(s):
return 'Underflow occurs'
else:
val=s.pop()
if len(s)==0:
top=None
else:
top=len(s)-1
return val
def show(s):
if isEmpty(s):
print('no item found')
else:
t=len(s)-1
print('(TOP)',end='')
while(t>=0):
print(s[t],'<==',end='')
t=t-1
print()
s=[]
top=None
while True:
print('****** STACK IMPLEMENTATION USING LIST ******')
print('1: PUSH')
print('2: POP')
26
print('3: Show')
print('0: Exit')
ch=int(input('Enter choice:'))
if ch==1:
val= input('Enter name to push:')
push(s,val)
elif ch==2:
val=pop(s)
if val=='Underflow':
print('Stack is empty')
else:
print('\nDeleted item is:',val)
elif ch==3:
show(s)
elif ch==0:
print('Bye')
break
Output :
27
Program number – 16 : Table creation using python and MySQL
Date : 23-10-2024
AIM : To write a python script to create table using MySQL.
Program :
import mysql.connector
#establishing the connection
db=mysql.connector.connect(host="localhost",user="root",passwd="chinny@123",
database="mydb")
#Creating a cursor object using the cursor() method
cursor = db.cursor()
#Dropping EMPLOYEE table if already exists.
cursor.execute("DROP TABLE IF EXISTS EMPLOYEE")
#Creating table as per requirement
cursor.execute('''CREATE TABLE EMPLOYEE( EMP_ID INT(3) PRIMARY
KEY, FIRST_NAME CHAR(20),
LAST_NAME CHAR(20), AGE INT(2),
SEX CHAR(1))''')
#Commit your changes in the database
db.commit()
#Closing the connection
db.close()
Output :
28
Program number – 17 : Inserting records into table using python and
MySQL
Date : 23-10-2024
AIM : To write a python script to insert records into MySQL table.
Program :
import mysql.connector
#establishing the connection
db=mysql.connector.connect(host="localhost",user="root",passwd="chinny@123",
database="mydb")
#Creating a cursor object using the cursor() method
cursor = db.cursor()
#Creating table as per requirement
cursor.execute('''INSERT INTO EMPLOYEE(EMP_ID, FIRST_NAME,
LAST_NAME, AGE, SEX) VALUES(2,'Labour','India',35,'M')''')
#Commit your changes in the database
db.commit()
#Closing the connection
db.close()
29
Output :
30
Program number – 18 : Updating records in table using python and
MySQL
Date : 23-10-2024
AIM : To write a python script to update records in MySQL table.
Program :
import mysql.connector
#establishing the connection
db=mysql.connector.connect(host="localhost",user="root",passwd="chinny@123",
database="mydb")
#Creating a cursor object using the cursor() method
cursor = db.cursor()
#Updating table as per requirement
cursor.execute('UPDATE EMPLOYEE SET AGE=45 WHERE EMP_ID=1')
#Commit your changes in the database
db.commit()
#Closing the connection
db.close()
Output :
31
Program number – 19 : Deleting records from table using python and
MySQL
Date : 01-11-2024
AIM : To write a python script to delete records from python table.
Program :
import mysql.connector
#establishing the connection
db=mysql.connector.connect(host="localhost",user="root",passwd="chinny@123",
database="mydb")
#Creating a cursor object using the cursor() method
cursor = db.cursor()
#Updating table as per requirement
cursor.execute('DELETE FROM EMPLOYEE WHERE EMP_ID=1')
#Commit your changes in the database
db.commit()
#Closing the connection
db.close()
Output :
32
Program number – 20 : Fetching records from table using python and
MySQL
Date : 01-11-2024
-1 AIM : To write a python script to fetch records from MySQL table.
Program :
import mysql.connector
#establishing the connection
db=mysql.connector.connect(host="localhost",user="root",passwd="chinny@123",
database="mydb")
#Creating a cursor object using the cursor() method
cursor = db.cursor()
#Retrieving data from table
cursor.execute('SELECT * from EMPLOYEE')
#Fetching 1st row from the table
result = cursor.fetchone();
print(result)
#Fetching 1st row from the table
result1 = cursor.fetchall();
print(result1)
#Commit your changes in the database
db.commit()
#Closing the connection
db.close()
33
Output :
34
Program number – 21 : Fetching records from table using python and MySQL
Date : 01-11-2024
AIM : To write a python script to fetch records from MySQL table with condition.
Program :
import mysql.connector
#establishing the connection
db=mysql.connector.connect(host="localhost",user="root",passwd="chinny@123",
database="mydb")
#Creating a cursor object using the cursor() method
cursor = db.cursor()
#Retrieving specific records using the where clause
cursor.execute("SELECT * from EMPLOYEE WHERE AGE <40")
result = cursor.fetchall()
print(result)
#Commit your changes in the database
db.commit()
#Closing the connection
db.close()
Output :
35
Program number – 22 : Joining 2 tables using python and MySQL
Date : 08-11-2024
AIM : To write a program to generate a random number between 0 and 9
Program :
import mysql.connector
#establishing the connection
db=mysql.connector.connect(host="localhost",user="root",passwd="chinny@123",
database="mydb")
#Creating a cursor object using the cursor() method
cursor = db.cursor()
#Retrieving specific records using the where clause
cursor.execute('''SELECT * from EMPLOYEE INNER JOIN
EMP_SAL ON EMPLOYEE.FIRST_NAME = EMP_SAL.FIRST_NAME''')
result = cursor.fetchall()
print(result)
#Commit your changes in the database
db.commit()
#Closing the connection
db.close()
36
Output :
37
Program number – 23 : MySQL Commands – Simple Queries.
Date : 09-11-2022
AIM : To execute simple MySQL queries.
Script :
10.1 – select all from table ‘EMPLOYEE’ in database ‘mydb’
USE mydb;
SELECT * FROM EMPLOYEE ;
10.2 – select selected columns from table ‘EMPLOYEE’ in database ‘mydb’
USE mydb;
SELECT EMP_ID, FIRST_NAME FROM EMPLOYEE;
38
Output :
39
Program number – 24 : MySQL Commands – Selection Queries.
Date : 08-11-2024
AIM : To execute selection based MySQL queries.
Script :
11.1 – select ‘FIRST_NAME’ from table ‘EMPLOYEE’ in database ‘mydb’ with age
> 30.
USE mydb;
SELECT FIRST_NAME FROM EMPLOYEE WHERE AGE>30;
40
Output :
41
Program number – 25 : MySQL Commands – Functions and Grouping.
Date : 08-11-2024
AIM : To execute built in commands in MySQL.
Script :
12.1 - select average value of ‘AGE’ from table ‘EMPLOYEE’ in database ‘mydb’.
USE mydb;
SELECT AVG(AGE) FROM EMPLOYEE;
12.2 - total count of employees from table ‘EMPLOYEE’ in database ‘mydb’ grouped by
‘AGE’.
USE mydb
SELECT AGE, COUNT(*) FROM EMPLOYEE GROUP BY AGE;
12.3 – change all characters to uppercase ‘FIRST_NAME’ in table
‘EMPLOYEE’
USE mydb
SELECT UPPER(FIRST_NAME) FROM EMPLOYEE ;
42
Output :
43