Practical File Term 1 2025-2026
Practical File Term 1 2025-2026
1. Double the odd values and half the even values using
function(LIST)
AIM- To write a program to pass list to a function and double the odd values and
half even values of a list and display list element after changing using function.
OUTPUT:
OUTPUT:
RESULT:
Thus, by using python coding string functions are implemented successfully.
4. FIND INDEX POSITION OF AN ELEMENT WITHOUT USING
index()
AIM: To write a python function to find an element’s index/position in a tuple
without using index() method.
SOFTWARE USED: IDLE (PYTHON 3.8 64-BIT)
PROGRAM:
tuple1=eval(input("Enter the tuple values only numbers:"))
F=int(input("Enter a value to find the Index Number:"))
def Index_tup( tuple1,F):
if F in tuple1:
count=0
for a in tuple1:
if a!=F:
count+=1
else:
break
print(F,'is at index',count,'in',tuple1)
else:
print(F,"is not in the tuple1")
Index_tup( tuple1,F)
OUTPUT:
RESULT:
Thus by using python coding Index/ Position of the given element is found
successfully
OUTPUT:
RESULT: Thus by using python coding dictionaries are created and updated
successfully.
6. TEXT FILE - REMOVE ALL LINES THAT CONTAINS ‘A’ IN A FILE AND
WRITE INTO ANOTHER FILE.
AIM: To write a python program to remove all the lines that contain the character
‘a’ in a file and write it to another file.
PROGRAM:
def Removea():
f=open("text.txt","r")
f1=open("text2.txt","w")
f2=open("text3.txt","w")
line=f.readlines()
for i in line:
if 'a' in i or 'A' in i:
f1.write(i)
else:
f2.write(i)
f.close()
f1.close()
f2.close()
Removea()
RESULT:
Thus, by using python program all the lines that contain the character ‘a’ in a file is
removed and written it to another file successfully.
AIM: To write a python program to read a text file and a function in python to count the
number lines in a text file ‘Sample.txt’ which is starting with an alphabet ‘W’ or ‘A’.
SOFTWARE USED- IDLE (PYTHON 3.8 64-BIT)
PROGRAM:
OUTPUT:
RESULT:
Thus, by using a python program a text file ‘Sample.txt’ is read and
the number of lines which start with an alphabet ‘W’ or ‘A’ are
counted successfully.
8. READ A TEXT FILE LINE BY LINE AND DISPLAY
EACH WORD SEPARATED BY A #
AIM- To Write a python function Add() to read and display file content line by
line with each word separated by #
PROGRAM:
def Add():
f=open("Text.txt","r")
line=f.readlines()
for i in line:
s=i.split()
for j in s:
print(j,end='#')
print()
f.close()
Add()
OUTPUT:
RESULT:
Thus, by using a python program a text file ‘Text.txt’ is read and display file content line
by lines with each word separated by #.
9. READ A TEXT FILE LINE BY LINE AND DISPLAY THE LINES WHICH
CONTAIN THE WORD ‘network’.
AIM: To write a python function to read a text file ‘NETWORK.TXT’ and display the
lines which contain the word ‘network’.
PROGRAM:
def SearchNet():
f=open("NETWORK.txt","r")
line=f.readlines()
for i in line:
s=i.split()
for j in s:
if j=='Network' or j=='network':
print(i)
f.close()
SearchNet()
OUTPUT:
RESULT:
Thus, Thus, by using a python program a text file ‘NETWORK.txt’ is read and the
lines which contain the word ‘network’ are printed successfully.
10. BINARY FILE CREATE
AIM: To write a python function CreateBin() to create a binary file with [sid,sname,class, mark] whose
mark is greater than 70.
PROGRAM:
def createbin():
import pickle
f=open('Student.dat','wb')
n=int(input('Enter the No. of Records:'))
for i in range(n):
R=int(input('Enter the Roll No:'))
N=input('Enter the Student Name:')
C=input("Enter the class:")
M=int(input('Enter the mark:'))
L=[R,N,C,M]
if M>70:
print(L)
pickle.dump(L,f)
print("File Created Successfully")
f.close()
createbin()
OUTPUT
RESULT:
Thus, a binary file is created and students' records are inserted into the file ‘Student.dat’
successfully.
11 BINARY FILE SEARCH AND DISPLAY
AIM: To Write a python function SearchRoll() to create a binary file with name and roll number. Search
for a given roll number and display the name, if not found display an appropriate message.
PROGRAM:
def SearchRoll():
import pickle
f=open("file.dat","wb")
l=[]
ans="y"
while ans=="y":
a=int(input("Enter the rollno:"))
b=input("Enter the name:")
l=[a,b]
pickle.dump(l,f)
ans=input("Enter your choice:")
f.close()
f1=open("file.dat","rb")
l1=[]
rno=int(input("Enter the rollno to search:"))
found=False
try:
while True:
l1=pickle.load(f1)
if l1[0]==rno:
print(l1[1])
found=True
except EOFError:
if found==False:
print("No such records")
f1.close()
SearchRoll()
OUTPUT:
RESULT:
Thus, a binary file is created with name and roll number. Search
for a given roll number and display the name, if not found display an appropriate message is printed
successfully.
OUTPUT:
RESULT:
Thus, by using python a binary file is created and the salary was updated successfully.
OUTPUT:
RESULT:
Thus,by using a python program a CSV file is created and password is searched
and displayed successfully.
OUTPUT: