VELAMMAL BODHI CAMPUS
XII-COMPUTER SCIENCE (083)
LIST OF RECORD PROGRAMS IN DETAIL
INSTRUCTIONS TO WRITE RECORD:
1. Kindly avoid using correction pen in record note book
2. Every program to be written in new page
3. Use only Blue and Black pen
4. Write heading and sub headings with black pen otherwise blue pen
5. Use pencil to write output
6. Draw line at the end of each program
7. Write date and program number in top corner
8. In index page write date (pen) , program name in (pen) and page no (pencil)
9. Maintain proper indent in each line of the program
NOTE: A Sample Program to be written on the right side of the record book
NOTE: A Sample OUTPUT to be written on the left side of the record book
TERM – 1
Program-1
DATE : 21.06.2021
Topic: LINEAR SEARCH
AIM:
To write a python program to search for a specific element using linear search
SOURCE CODE:
def LINEAR(a,key):
for i in a:
if i==key:
print(key,"found at location",a.index(key))
break
else:
print("Element not found")
a=eval(input("Enter the list of elements"))
key=eval(input("Enter the key to be searched"))
LINEAR(a,key)
RESULT:
The program executed successfully
OUTPUT:
Program-2
Date: 24.06.2021
Topic: SWAPPING FIRST HALF WITH SECOND HALF IN THE LIST
AIM:
To write a python program to swap first half of the list with second half in a list
SOURCE CODE:
def SWAP(a):
if len(a)%2==0:
j=len(a)//2
else:
j=len(a)//2+1
i=0
while i<len(a)//2:
a[i],a[j]=a[j],a[i]
i+=1
j+=1
print("After swapping the list is",a)
a=eval(input("Enter the list of elements"))
SWAP(a)
RESULT:
The program executed successfully
OUTPUT:
Program-3
Date: 29.06.2021
Topic: TUPLE MAXIMUM
AIM:
To write a python program to find the largest in a given tuple (without max() function).
SOURCE CODE:
def Largest(a):
lar=a[0]
for i in a[1:]:
if i>lar:
lar=i
print("Largest is ",lar)
a=eval(input("Enter a tuple"))
Largest(a)
RESULT:
The program executed successfully
OUTPUT:
Program-4
Date: 09.07.2021
Topic: NUMBER PALINDROME
AIM:
To write a python program to check whether the inputted number is palindrome or not
SOURCE CODE:
def PALINDROME(n):
temp=n
r=0
while n>0:
d=n%10
r=(r*10)+d
n=n//10
if temp==r:
print(temp,"is palindrome")
else:
print(temp,"is not palindrome")
n=int(input("Enter a number"))
PALINDROME(n)
RESULT:
The program executed successfully
OUTPUT:
Program-5
Date: 13.07.2021
Topic: VOWEL COUNTING IN A STRING
AIM:
To write a python program to count vowels in an inputted string
SOURCE CODE:
def COUNT(a):
c=0
for i in a:
if i in'aeiouAEIOU':
c+=1
print("Total number of vowels are",c)
a=input("Enter a string")
COUNT(a)
RESULT:
The program executed successfully
OUTPUT:
Program-6
Date: 22.07.2021
Topic: COPY CONSONANTS FROM ONE TEXT FILE TO ANOTHER FILE
AIM:
To write a python program to copy all the consonants from file1.txt to file2.txt
SOURCE CODE:
f1=open("file1.txt",'r')
f2=open("file2.txt",'w')
data=f1.read()
for i in data:
if i not in 'AEIOUaeiou':
f2.write(i)
f1.close()
f2.close()
RESULT:
The program executed successfully
OUTPUT:
Program-7
Date: 29.07.2021
Topic: DISPLAY OF FIVE LETTER WORDS FROM A TEXT FILE
AIM:
To write a python program to print all the five letter words from text file File1.txt
SOURCE CODE:
f=open("file1.txt",'r')
c=0
data=f.read()
data=data.split()
print("Five letter words present in the text file are")
for i in data:
if len(i)==5:
print(i)
f.close()
RESULT:
The program executed successfully
OUTPUT:
Program – 8
Date: 05.08.2021
Topic: FREQUENCY OF "ME" OR "MY" WORDS PRESENT IN A TEXT FILE
AIM:
To write a python program to count the occurrences of the words "Me" & "My" from text file
file1.txt
SOURCE CODE:
f=open("file1.txt",'r')
c=0
data=f.read()
data=data.split()
for i in data:
if i.lower()=="me" or i.lower()=="my" :
c=c+1
print("No of occurrences of the words Me & My is", c)
f.close()
RESULT:
The program executed successfully
OUTPUT:
Program-9
Date: 12.08.2021
Topic: DISPLAY OF LINES STARTING WITH 'I'
AIM:
To write a python program to display all the lines starting with ‘I’ from text file File1.txt
SOURCE CODE:
f=open("file1.txt",'r')
data=f.readlines()
for i in data:
if i[0]=='I':
print(i,end='')
f.close()
RESULT:
The program executed successfully
OUTPUT:
Program: 10
Date: 19.08.2021
Topic:
REMOVE ALL THE LINES THAT CONTAIN THE CHARACTER 'A' IN A FILE AND WRITE IT
TO ANOTHER FILE
AIM:
To remove all the lines that contains the character ‘a’ in a file and writes it to another file.
SOURCE CODE:
f1=open("file1.txt",'r')
f2=open("file2.txt",'w')
data=f1.readlines()
for i in data:
if 'a' not in i:
f2.write(i)
f1.close()
f2.close()
RESULT:
The program executed successfully
OUTPUT:
Program-11
Date: 08.09.2021
Topic: WRITING, READING AND DISPLAY IN A BINARY FILE
AIM:
To write a python program to display to write, read and display the content of a binary file
SOURCE CODE:
import pickle
f=open("student.dat",'wb+')
n=int(input("Enter the number of students:"))
rec=[]
for i in range(n):
rno=int(input("Enter the student roll number:"))
name=input("Enter the student name:")
marks=float(input("Enter the student marks:"))
data=[rno,name,marks]
rec.append(data)
pickle.dump(rec,f)
f.seek(0)
try:
while True:
s=pickle.load(f)
for i in s:
print(i)
except EOFError:
pass
f.close()
RESULT:
The program executed successfully
OUTPUT:
Program-12
Date: 16.09.2021
Topic: WRITING, READING AND SEARCHING IN A BINARY FILE
AIM:
To write a python program to display to search and display the content of a binary file
SOURCE CODE:
import pickle
f=open("student.dat",'wb+')
n=int(input("Enter the number of students:"))
rec=[]
for i in range(n):
rno=int(input("Enter the student roll number:"))
name=input("Enter the student name:")
marks=float(input("Enter the student marks:"))
data=[rno,name,marks]
rec.append(data)
pickle.dump(rec,f)
f.seek(0)
no=int(input("Enter the rollnumber to search a record:"))
print("SEARCHING RECORD IS:")
try:
while True:
s=pickle.load(f)
for i in s:
if(i[0]==no):
print(i)
except EOFError:
pass
f.close()
RESULT:
The program executed successfully
OUTPUT:
Program-13
Date: 28.09.2021
Topic: WRITING, READING AND SEARCHING ON CSV FILE
AIM:
To write a python program to perform search and display operations in a CSV file.
SOURCE CODE:
import csv
student=[(1,'Lata',450),(2,'Anil',496),(3,'John',390)]
f=open('students.csv','a', newline='')
obj=csv.writer(f)
for stud in student:
obj.writerow(stud)
f.close()
f=open('students.csv','r', newline='')
obj=csv.reader(f)
print("The details in the files are")
for i in obj:
print(i)
f.close()
f=open('students.csv','r', newline='')
n=input("Enter the name to be searched")
obj=csv.reader(f)
for stud in obj:
if n in stud:
print("The details are")
print (stud)
break
else:
print("Data is not available")
f.close()
RESULT:
The program executed successfully
OUTPUT:
Program-14
Date: 06.10.2021
Topic: PRIME OR NOT
AIM:
To write a python program to check whether an inputted number is prime or not
SOURCE CODE:
n=int(input("Enter the number"))
for i in range(2,n):
if n%i==0:
print(n,"is not prime")
break
else:
print(n,"is prime")
RESULT:
The program executed successfully
OUTPUT:
Program-15
Date: 27.10.2021
Topic: GENERATION OF A RANDOM NUMBER WITH IN THE GIVEN RANGE
AIM:
To write a python program to generate a random number between an upper limit and lower limit
SOURCE CODE:
import random
l=int(input("Enter the lower limit"))
u=int(input("Enter the upper limit"))
print(random.randint(l,u))
RESULT:
The program executed successfully
OUTPUT:
TERM – 2
Program-16
Date: 05.01.2022
Topic: PUSH AND DISPLAY OPERATIONS ON STACK
AIM:
To write a python program to implement push operations in a stack
SOURCE CODE:
a=[]
def PUSH():
n=int(input("Enter the number of elements to be pushed"))
for i in range(n):
ele=int(input("Enter the element"))
a.append(ele)
def DISPLAY():
if len(a)==0:
print("Underflow")
else:
print("Elements are”, a[::-1])
PUSH()
DISPLAY()
RESULT:
The program executed successfully
OUTPUT:
Program-17
Date: 24.01.2022
Topic: POP AND DISPLAY OPERATIONS ON STACK
AIM:
To write a python program to implement pop operations in a stack
SOURCE CODE:
a=[20,30,40]
def POP():
if len(a)==0:
print("Underflow")
else:
print("Deleted element is", a.pop())
def DISPLAY():
if len(a)==0:
print("Underflow")
else:
print("Elements are",a[::-1])
print("Stack before deletion (Pop):\nElements are:",a[::-1])
POP()
print("Stack after deletion(Pop):")
DISPLAY()
RESULT:
The program executed successfully
OUTPUT:
Program-18
Date: 31.01.2022
Topic: ENQUEUE AND DISPLAY OPERATIONS ON QUEUE
AIM:
To write a python program to implement insert operations in a queue
SOURCE CODE:
a=[]
def INSERT():
n=int(input("Enter the number of elements to be added"))
for i in range(n):
ele=int(input("Enter the element"))
a.append(ele)
def DISPLAY():
if len(a)==0:
print("Underflow")
else:
print("Elements are",a)
INSERT()
DISPLAY()
RESULT:
The program executed successfully
OUTPUT:
Program-19
Date: 04.02.2022
Topic: DEQUEUE AND DISPLAY OPERATIONS ON QUEUE
AIM:
To write a python program to implement delete operations in a queue
SOURCE CODE:
a=[10,20,30,40]
def DELETE():
if len(a)==0:
print("Underflow")
else:
print("Deleted element is",a.pop(0))
def DISPLAY():
if len(a)==0:
print("Underflow")
else:
print("Elements are",a)
print("Queue before deletion:\n Elements are:",a)
DELETE()
print("Queue After deletion:")
DISPLAY()
RESULT:
The program executed successfully
OUTPUT:
Program-20
Date: 08.02.2022
Topic: CREATE AND DISPLAY TABLE
AIM:
To write a Python-SQL connectivity program to create a database 'EMPLOYEE' , table 'DATA'
using below information and display it.
EMPNO EMPNAME SALARY EXPERIENCE
1 Ram 25000 5
2 'Rohith' 20000 4
3 'Ann' 35000 7
4 'Aman' 15000 2
5 'Ranjini' 26000 6
SOURCE CODE:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="admin")
mycursor=mydb.cursor()
mycursor.execute("CREATE DATABASE EMPLOYEE")
mycursor.execute("USE EMPLOYEE")
mycursor.execute("CREATE TABLE DATA (EMPNO INT,EMPNAME CHAR(10),SALARY
FLOAT,EXPERIENCE INT)")
mycursor.execute("INSERT INTO DATA VALUES(1,'Ram',25000,5)")
mycursor.execute("INSERT INTO DATA VALUES(2,'Rohith',20000,4)")
mycursor.execute("INSERT INTO DATA VALUES(3,'Ann',35000,7)")
mycursor.execute("INSERT INTO DATA VALUES(4,'Aman',15000,2)")
mycursor.execute("INSERT INTO DATA VALUES(5,'Ranjini',26000,6)")
mycursor.execute("SELECT * FROM DATA")
for i in mycursor:
print(i)
RESULT:
The program executed successfully
OUTPUT:
Program-21
Date: 12.02.2022
Topic: CREATE AND SEARCH IN A TABLE
AIM:
To write a Python-SQL connectivity program to create a table to create a database ‘EMPLOYEE’,
table 'DATA' and search for a specific data from it.
EMPNO EMPNAME SALARY EXPERIENCE
1 Ram 25000 5
2 'Rohith' 20000 4
3 'Ann' 35000 7
4 'Aman' 15000 2
5 'Ranjini' 26000 6
SOURCE CODE:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="admin")
mycursor=mydb.cursor()
mycursor.execute("CREATE DATABASE EMPLOYEE")
mycursor.execute("USE EMPLOYEE")
mycursor.execute("CREATE TABLE DATA (EMPNO INT,EMPNAME CHAR(10),SALARY
FLOAT,EXPERIENCE INT)")
mycursor.execute("INSERT INTO DATA VALUES(1,'Ram',25000,5)")
mycursor.execute("INSERT INTO DATA VALUES(2,'Rohith',20000,4)")
mycursor.execute("INSERT INTO DATA VALUES(3,'Ann',35000,7)")
mycursor.execute("INSERT INTO DATA VALUES(4,'Aman',15000,2)")
mycursor.execute("INSERT INTO DATA VALUES(5,'Ranjini',26000,6)")
mycursor.execute("SELECT * FROM DATA where EMPNO=2")
for i in mycursor:
print(i)
RESULT:
The program executed successfully
OUTPUT:
Program-22
Date: 03.03.2022
Topic: CREATE AND UPDATION IN A TABLE
AIM:
To write a Python-SQL connectivity program to create a database ‘EMPLOYEE’, table 'DATA' and
update data in it.
EMPNO EMPNAME SALARY EXPERIENCE
1 Ram 25000 5
2 'Rohith' 20000 4
3 'Ann' 35000 7
4 'Aman' 15000 2
5 'Ranjini' 26000 6
SOURCE CODE:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="admin")
mycursor=mydb.cursor()
mycursor.execute("CREATE DATABASE EMPLOYEE")
mycursor.execute("USE EMPLOYEE")
mycursor.execute("CREATE TABLE DATA (EMPNO INT,EMPNAME CHAR(10),SALARY
FLOAT,EXPERIENCE INT)")
mycursor.execute("INSERT INTO DATA VALUES(1,'Ram',25000,5)")
mycursor.execute("INSERT INTO DATA VALUES(2,'Rohith',20000,4)")
mycursor.execute("INSERT INTO DATA VALUES(3,'Ann',35000,7)")
mycursor.execute("INSERT INTO DATA VALUES(4,'Aman',15000,2)")
mycursor.execute("INSERT INTO DATA VALUES(5,'Ranjini',26000,6)")
mycursor.execute("UPDATE DATA SET SALARY =SALARY+1000")
mycursor.execute("SELECT * FROM DATA")
for i in mycursor:
print(i)
RESULT:
The program executed successfully
OUTPUT:
Before Updation:
After Updation:
Program-23
Date: 10.03.2022
Topic: CREATE AND DELETION IN A TABLE
AIM:
To write a Python-SQL connectivity program to create a database 'EMPLOYEE' , table 'DATA' and
delete a specific record in it.
EMPNO EMPNAME SALARY EXPERIENCE
1 Ram 25000 5
2 'Rohith' 20000 4
3 'Ann' 35000 7
4 'Aman' 15000 2
5 'Ranjini' 26000 6
SOURCE CODE:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="admin")
mycursor=mydb.cursor()
mycursor.execute("CREATE DATABASE EMPLOYEE")
mycursor.execute("USE EMPLOYEE")
mycursor.execute("CREATE TABLE DATA (EMPNO INT,EMPNAME
CHAR(10),SALARY FLOAT,EXPERIENCE INT)")
mycursor.execute("INSERT INTO DATA VALUES(1,'Ram',25000,5)")
mycursor.execute("INSERT INTO DATA VALUES(2,'Rohith',20000,4)")
mycursor.execute("INSERT INTO DATA VALUES(3,'Ann',35000,7)")
mycursor.execute("INSERT INTO DATA VALUES(4,'Aman',15000,2)")
mycursor.execute("INSERT INTO DATA VALUES(5,'Ranjini',26000,6)")
mycursor.execute("DELETE FROM DATA WHERE EMPNO=5")
mycursor.execute("SELECT * FROM DATA")
for i in mycursor:
print(i)
RESULT:
The program executed successfully
OUTPUT:
Before Deletion: After Deletion: