0% found this document useful (0 votes)
29 views15 pages

Practical File Term 1 2025-2026

The document outlines a practical program for Class XII Computer Science at Shree Niketan Patasala for the term 2025-2026. It includes various Python programming tasks such as manipulating lists, strings, dictionaries, and files, along with their respective aims, programs, and results. Each task demonstrates different functionalities of Python, including list operations, file handling, and data structures like stacks.

Uploaded by

sp20101810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views15 pages

Practical File Term 1 2025-2026

The document outlines a practical program for Class XII Computer Science at Shree Niketan Patasala for the term 2025-2026. It includes various Python programming tasks such as manipulating lists, strings, dictionaries, and files, along with their respective aims, programs, and results. Each task demonstrates different functionalities of Python, including list operations, file handling, and data structures like stacks.

Uploaded by

sp20101810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

SHREE NIKETAN PATASALA

TERM -1 PRACTICAL PROGRAM -2025-2026


CLASS: XII​ ​ ​ COMPUTER SCIENCE

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.

SOFTWARE USED- IDLE (PYTHON 3.8 64-bit)


PROGRAM:
#TO PASS LIST & DOUBLE THE ODD VALUES AND HALF EVEN
VALUES & DISPLAY THE CHANGED LIST
def f(l):
l2=[]
for i in range(0,len(l)):
if l[i]%2==0:
e=l[i]/2
l2.append(e)
else:
e=l[i]*2
l2.append(e)
print(l2)
a=eval(input("Entera list :"))
f (a)
RESULT:
Thus by using Python code the odd elements in the list get doubled and half
even values it can print on the screen.
2.​ IMPLEMENTING PYTHON LIST FUNCTIONS
AIM: To write a python program to implement list functions using user
defined functions.
SOFTWARE USED: IDLE (PYTHON 3.8 64-BIT)
PROGRAM:
# Implementing List built-in functions
L=eval(input("Enter the list:"))
def list_fun(L):
print("Length of the list:",len(L))
L.sort()
print("After sorting the list:",L)
L.reverse()
print("After Reversing the list:",L)
L.append([8,9])
print("After appending the element in the list:",L)
L.extend([23,51,17])
print("After extending the element in the list:",L)
print("Count of the given element:", L.count(5))
L.insert(34,2)
print("After inserting one element in the present list:",L)
print("Deleting the last element from the list:",L.pop())
list_fun(L)
RESULT:
Thus by using python coding List inbuilt function is implemented successfully.

OUTPUT:

3.​ IMPLEMENTING PYTHON STRING FUNCTIONS

AIM- To write a python program to implement python string functions

SOFTWARE USED- IDLE (PYTHON 3.8 64-BIT)


PROGRAM:
#TO IMPLEMENT PYTHON STRING FUNCTIONS
def strfun():
c=str(input("Enter sentence :"))
a=input("enter the spacing :")
print("The string entered is a word:", c. isalpha ())
print("The string entered in lower case :",c.lower())
print("The string entered is in lower case : ", c. islower())
print("The string entered in upper case :",c.upper())
print("The string entered is in upper case : ", c. isupper ())
print("The string entered after removing the space from left side :",c.lstrip())
print("The string entered after removing the space from right side :", c. rstrip())
print("The string entered contains whitespace :",c.isspace())
print("The string entered is titlecased :",c.istitle())
print("The string entered after joining with ",a,":", a. join(c))
print("The string entered after swapping case : ", c. swapcase ())
strfun()

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

5. CREATE AND UPDATE DICTIONARY


AIM: To write a python program to create a dictionary with key and value and
update value at that key using a function.
SOFTWARE USED: IDLE (PYTHON 3.8 64-BIT)
PROGRAM:
#TO UPDATE THE KEY AND VALUE OF EXISTING DICT ENTERED BY
USER
def fun (d,k):
value2=eval(input ("Enter the value :" ) )
d [k]=value2
print("updated dictionary :",d)
x=int(input("Number of pairs in dictionary :"))
Dic={}
for i in range (x):
key=input("Enter the key :")
value=eval(input("Enter the value :"))
Dic[key]=value
print("Original dictionary :",Dic)
a= input ("Enter the key whose value you want to change :")
fun(Dic,a)

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.

7. TEXT FILE- A FUNCTION IN PYTHON TO COUNT THE NUMBER LINES IN


A TEXT FILE ‘SAMPLE.TXT’ WHICH IS STARTING WITH AN ALPHABET
‘W’ OR ‘A’.

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.

12. ​​ ​ ​ BINARY FILE - CREATE AND UPDATE


AIM: To write a program to create a binary file with ENo, Ename, Designation, salary
and update the salary by adding 500 for the employee whose salary is greater than 60000.
PROGRAM:
import pickle
def createbin():
f=open('Emp.dat','wb')
n=int(input('Enter the No. of Records:'))
for i in range(n):
R=int(input('Enter the EID:'))
N=input('Enter the EName:')
C=input("Enter the Designation:")
M=int(input('Enter the Salary:'))
L=[R,N,C,M]
pickle.dump(L,f)
print("File Created Sucessfully")
f.close()
createbin()
def updatebin():
f=open('Emp.dat','rb+')
found=True
try:
while True:
p=f.tell()
a=pickle.load(f)
if a[3]>60000:
a[3]+=500
f.seek(p)
pickle.dump(a,f)
found=False
except EOFError:
if found==True:
print('No Such Record found!!')
else:
print("Record found successfully")
f.close()
updatebin()

OUTPUT:
RESULT:
Thus, by using python a binary file is created and the salary was updated successfully.

13. ​ ​ ​ ​ CSV FILE - CREATE AND SEARCH & DISPLAY


AIM: To Write a python function to create a CSV file by entering user-id and password, read
and search the password for the given userid
PROGRAM:
def CreateCSV():
import csv
f=open("login.csv",'w')
a=csv.writer(f)
ans= 'y'
while ans=='y':
uid = input("Enter the user id to login in:")
psw=input("Enter the password to login in:")
a.writerow([uid,psw])
ans=input("Do you want to enter more record?(yln):")
f. close()
CreateCSV()
def SearchCSV():
f1 =open("login.csv",'r',newline='\n')
R=[]
R=csv.reader(f1)
U=input('Enter the user id to search:')
for i in R:
if i[0]==U:
print(i[1])
f1.close()
SearchCSV()

OUTPUT:

RESULT:
​ Thus,by using a python program a CSV file is created and password is searched
and displayed successfully.

14.​ ​ ​ CSV FILE - CREATE AND DISPLAY


AIM: To Write a python function to create a CSV file by by entering Furniture id, Name of
the furniture, Price of furniture and display the furniture id and name whose price is more than
10000.
PROGRAM:
import csv
def CreateFun():
f=open("furdata.csv",'w')
a=csv.writer(f)
n=int(input('Enter the No. of Records:'))
for i in range(n):
fid = int(input("Enter the Furniture id:"))
name=input("Enter the Name of the furniture :")
p=int(input("Enter the Price of furniture:"))
a.writerow([fid,name,p])
f. close()
CreateFun()
def Searchdis():
f1 =open("furdata.csv",'r',newline='\n')
R=[]
R=csv.reader(f1)
for i in R:
if int(i[2])>10000:
print(i[0],',',i[1])
f1.close()
Searchdis()

OUTPUT:

15. ​ ​ ​ ​ ​ STACK OPERATION


AIM: To Write a Python program to implement a stack operation PUSH and POP using list.​
PROGRAM:
def Push(v,stack):
stack.append(v)
def pop(stack):
return stack.pop()
def display():
return stack
stack = []
while True:
print("Stack Operation")
print("1. PUSH")
print("2. POP")
print("3. Exit")
ch=int(input("Enter ur choice"))
if ch==1:
v=int(input("Enter the element to push into the stack:"))
Push(v,stack)
elif ch==2:
print("Deleted element is :",pop(stack))
elif ch==3:
print("Stack =",display())
break
OUTPUT:
RESULT:
Thus, by using python stack operation PUSH and POP using list was implemented
successfully.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy