0% found this document useful (0 votes)
4 views

Practical file comp ( 25 python programs)-1

Uploaded by

navyagangwar510
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Practical file comp ( 25 python programs)-1

Uploaded by

navyagangwar510
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Shri Gulab Rai Montessori

Senior Secondary School

SeSSion: 2024 – 2025

Computer
Practical File

Submitted By: Submitted To:


Jahnavi Bhalla Mr. Manish Saxena

Class: XII - A1
Roll No. : 14
CERTIFICATE
This is to certify that Jahnavi Bhalla of class XII-A1
has successfully completed the
“Computer Project on FEE MANAGEMENT”
under my guidance during the year 2024-25 in the
partial fulfillment of the requirement of the Central
Board of Secondary Education
(C.B.S.E.)
It is further certified that this project is the
individual and bona fide work of the candidate.

___________ ___________
Principal's Teacher’s
Signature Signature
ACKNOWLEDGEMENT
It gives me immense pleasure to present the project –

"Computer Project"
In the accomplishment of this project successfully, many
people have bestowed upon me their blessings and their
heart pledged support. It would not have been possible
without the kind support of my teacher in charge,
Mr. Manish Saxena (PGT Computer) under whose
guidance and constant supervision the project was
brought to the present state. His suggestions and
instructions have served as the major contributors
towards the completion of the project.
I would also like to express my gratitude towards my
parents for their kind cooperation and encouragement
which helped me in the completion of this project. I am
also thankful to the C.B.S.E for giving me such an
amazing opportunity to do this project. Last but not the
least, I thank my friends who shared the necessary
information and useful web links for preparing my
project. Thanks again to all.
INDEX

S.No. Question Page No.

1 Write a Python program that finds the 1


no of vowels in a given statement
2 Write a program to check if a number 1
is a NEON number or not.
3 Write a program to check if a number 2
is a Perfect number or not.
4 Write a program to search any word in 2
given sentence.
5 Write a program to get a string from a
given string where all occurrences of 3
its first char have been changed to “$”
except the first char itself
6 Write a program to get the max and 4
min value in a dictionary
7 Write a Program to remove first 5
occurrence of a given element in the
list
8 Write a program to remove duplicate 6
elements from the list
9 Write a program to generate random no 7
from 1-6
10 Write a program to read the content of
a file story.txt and count the number of 8
occurrences of “me” separately
11 Write a program to read and display
file content line by line with each word 8
separated by “#”.
12 Write a function in python which
should read each character of the text
file "testfile.txt" and then count and 9
display the count of occurrence of the
alphabet "e"
13 Write a function reports the file's
longest line. 10
14 Writer function to input name,class,sec
of n students and store in binary file: 11
student.dat
15 Write a program to read binary file 12
student.dat and display all its record.
16 Write a function to update the data of
candidates whose experience is more
than 10 years and change their 12
designation to senior manager from the
file candidates.bin.
17 Write a program to accept roll number,
name and marks of 3 students and 13
store the data in a file student.csv.

18 Write a function to delete a data from 14


student.csv
19 Write a function which should push the
name of car manufactured by “TATA”
to the stack where vehicle is a 15
dictionary containing details of
vehicles.
20 Write a function python to add a new
package and delete a package from "a
list of package description" considering 16
them to act as push and pop operations
of the Stack Data structure
Practical No.1

Write a Python program that finds the no of vowels in a


given statement

CODE:
def count_vowels(st):
vowels = "aeiouAEIOU"
ct = 0
for i in st:
if i in vowels:
ct=ct+1
return ct
st= input("Enter String")
vc = count_vowels(st)
print("The number of vowels in",st," is:",vc)

OUTPUT

Practical No.2

Write a program to check if a number is a NEON number or


not.

CODE:
def neon():
num = int(input("Enter a number: "))
square = num ** 2
s = sum(int(digit) for digit in str(square))
if s== num:
print(num, "is a Neon number.")
else:
print(num, "is not a Neon number.")
neon()

OUTPUT

Practical No.3

Write a program to check if a number is a Perfect number or


not.
CODE
def perfect():
n=int(input("enter a number"))
s=0
for i in range(1,n):
if n%i==0:
s=s+i
if s==n:
print("perfect number")
else:
print("not")
perfect()

OUTPUT

Practical No.4

Write a program to search any word in a given sentence.


CODE
def countWord(str1,word):
s = str1.split()
count=0
for w in s:
if w==word: count+=1
return count
str1 = input("Enter any sentence:")
word = input("Enter word to search in sentence :")
count = countWord(str1,word)
if count==0:
print("## Sorry! ",word," not present ")
else:
print("## ",word," occurs ",count," times ## ")

OUTPUT

Practical No.5
Write a program to get a string from a given string where
all occurrences of its first char have been changed to “$”
except the first char itself.

CODE:
def req():
string=input("enter a string")
str=""
f=0
fs=string[0]
for i in string:
if i not in str:
str=str+i
elif i==fs:
str=str+"$"
else:
str=str+i
print(str)
req()

OUTPUT

Practical No.6
Write a program to get the max and min value in a dictionary.

CODE
def min_max():
dict={}
n=int(input("enter number of terms"))
for i in range(n):
name=input("enter name of srudent")
no=int(input("enter roll number"))
dict[name]=no
print("the original dictionary is",dict)
max=0
min=dict[name]
for i in dict:
if dict[i]>max:
max=dict[i]
if min>dict[i]:
min=dict[i]
print(max)
print(min)
min_max()

OUTPUT

Practical No.7
Write a Program to remove first occurrence of a given
element in the list.

CODE
def req():
k=[]
n=int(input("enter no of terms"))
print("enter",n,"nos with atleast one number being
repeated")
for i in range(n):
no=int(input())
k=k+[no]
print("original list is",k)
k1=[]
f=0
for i in k:
if i not in k1:
k1=k1+[i]
else:
f=f+1
if f>1:
if i not in k1:
k1=k1+[i]
else:
k1=k1+[i]
print("final list is",k1)
req()

OUTPUT

Practical No.8
Write a program to remove duplicate elements from the
list.

CODE
def req():
k=[]
n=int(input("enter no of elements in a list"))
print("enter",n, "nos in a list")
for i in range(n):
no=int(input())
k=k+[no]
print("original list is",k)
kf=[]
for i in k:
if i not in kf:
kf=kf+[i]
print("new list is ",kf)
req()

OUTPUT

Practical No.9
Write a program to generate random no from 1-6.

CODE
Import random
def roll():
return random.randint(1,6)
while True:
i=input(“roll?(y/n)”)
if i==”y”:
print(“you got”,roll())
elif i==”n”:
break
else:
print(“inavalid input”)

OUTPUT
Practical No.10
Write a program to read the content of a file story.txt and
count the number of occurrences of “the” separately.

CODE
f=open("story.txt")
data=f.read()
words=data.split()
me=0
for word in words:
if word.upper()=="ME":
me=me+1
print("Me occured ",me," times")

CONTENTS OF STORY.TXT

OUTPUT

Practical No.11
Write a program to read and display file content line by line
with each word separated by “#”.
CODE
def req():
f= open("file1.txt")
for line in f:
words= line.split()
for w in words:
print(w+'#',end=")
print()
f.close()
req()

CONTENTS OF FILE1:

OUTPUT

Practical No.12
Write a function in python which should read each
character of the text file "testfile.txt" and then count and
display the count of occurrence of the alphabet "e"

CODE
def ECount():
file = open ('TESTFILE.TXT', 'r')
Allines = file.readlines()
Ecount = 0
for w in Allines:
for ch in w:
if ch in 'Ee':
Ecount = Ecount + 1
print ("The number of E ore: ", Ecount)
file.close()

CONTENTS OF TESTFILE1:

OUTPUT

Practical No.13
Write a function that reports the file's longest line of a text
file.

CODE
def long():
f=open(“poem.txt”,”r”)
longest=””
s=f.readlines()
for line in s:
if len(line)>len(longest):
longest=line
print(longest)
long()

CONTENTS OF POEM.TXT
OUTPUT

Practical No.14
Writer function to input name,class,sec of n students and
store in binary file: student.dat

CODE
import pickle
f=open(“student.dat”,”wb”)
n=int(input(“enter no of records”))
k=[]
for I in range(n):
nm=input(“enter name”)
cl=input(“enter class”)
sec=input(“enter section”)
pickle.dump(k,f)
f.close()

OUTPUT

IDLE NOTEPAD
Practical No.15
Write a program to read binary file student.dat and display
all its record

CODE
import pickle
with open(“student.dat”,”rb”) as f
print(pickle.load(f))

OUTPUT

Practical No.16
Write a function to update the data of candidates whose
experience is more than 10 years and change their
designation to senior manager from the file candidates.dat

CODE
import pickle
def update_senior_manager():
updated_candidates = []
try:
with open('candidates.bin', 'rb') as file:
while True:
try:
candidate = pickle.load(file)
if candidate[3] > 10: # If experience > 10
years candidate[2] = 'Senior Manager'
updated_candidates.append(candidate)
except EOFError:
break
except FileNotFoundError:
print("No candidate data found. Please add
candidates first.")
return
with open('candidates.bin', 'wb') as file:
for candidate in updated_candidates:
pickle.dump(candidate, file)
print("Candidates updated to Senior Manager where
applicable.")
update_senior_manager()

OUTPUT

Practical No.17
Write a program to accept roll number, name and marks of
3 students and store the data in a file student.csv.

CODE
import csv
f=open("student.csv",'w',newline='\n')
w=csv.writer(f)
for i in range(3):
rno=int(input("Enter roll number of student"))
name=input("Enter name")
marks=float(input("Enter marks of student"))
a=[rno,name,marks]
w.writerow(a)
f.close()
OUTPUT

Practical No.18
Write a function to delete a data from student.csv

CODE
import csv
def delete():
rno=int(input("Enter roll number of student whose
details are to be deleted"))
f=open("student.csv")
r=csv.reader(f)
rows=[]
flag=0
for row in r:
if rno==int(row[0]):
flag=1
else:
rows.append(row)
f.close()
if flag==1:
f=open("student.csv",'w',newline='\n')
w=csv.writer(f)
w.writerows(rows)
f.close()
print("Row deleted")
else:
print("Invalid roll number entered")
delete()

OUTPUT

Practical No.19
Write a function which should push the name of car
manufactured by “TATA” to the stack where vehicle is a
dictionary containing details of vehicles.

CODE
def Push(k):
for i in k:
if k[i].upper()==”TATA”:
stk.insert(-1,i)
stk=[]
k={“santro”:”Hyundai”,”safari”:”tata”}
Push(k)
print(stk)

OUTPUT
Practical No.20
Write a function python to add a new package and delete a
package from "a list of package description" considering
them to act as push and pop operations of the Stack Data
structure

CODE
def Push(k):
a=int(input(“enter package title):
k.apppend(a)
print(k)
def POP_f(k):
if (k==[]):
print(“empty stack”)
else:
print(“deleted item id”,k.pop()

OUTPUT

You might also like