Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Computer Project

Uploaded by

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

Computer Project

Uploaded by

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

USHA MARTIN SCHOOL

NH – 34 Shimuldhab, Dhumadighi
Malda

COMPUTER SCIENCE PRACTICAL FILE

NAME – DHRUBAJYOTI SARKAR


CLASS - XII
SECTION – B2
ROLL NO. - 09
SESSION – 2024 - 2025
UNDER THE GUIDANCE OF – DIBYAJYOTI DAS
1. Read a text file line by line and display
each word separated by a #

f=open(r"C:\Users\user\Documents\Test.txt")
data=f.read()
a=data.split()
for i in a :
print(i+'#',end = '')

OUTPUT
2. Read a text file and display the number of
vowels/consonants/uppercase/lower-
case characters in the file

f=open(r'C:\Users\user\Documents\Test.txt')
data=f.read()
print(data)
print(" ")
vc=0
cc=0
uc=0
lc=0
for i in data:
if i.isalpha():
if i in 'AEIOUaeiou':
vc+=1
else:
cc+=1
if i.isupper():
uc+=1
if i.islower():
lc+=1
print("No.of Vowels in the file are:",vc)
print("No.of Consonants in the file are:",cc)
print("No. of uppercase characters in the file are:",uc)
print("No. of lowercase characters in the file are:",lc)

OUTPUT
3. Remove all the lines that contain the
character “a” in a file and write it to
another file

f=open(r'C:\Users\user\Documents\Test.txt')
data=f.readlines()
for i in data:
print(i)
f1=open(r'C:\Users\user\Documents\Test.txt','w')
f2=open(r'C:\Users\user\Documents\Test1.txt','w')
for i in data:
if 'a' in i:
f2.write(i)
else:
f1.write(i)

f1.close()
f2.close()
OUTPUT

4. Create a Binary file with name and roll


no. search for a given roll no. and display
the name, if not found display the
appropriate message
import pickle
fo=open("student.bin","wb")
dic={}
n=int(input("enter no. of students"))
for key in range(n):
rollNo=int(input("enter roll no"))
name=int(input("enter name"))
dic[rollNo]=name
pickle.dump(dic,fo)
fo.close()

#read binary file


fo=open("student.bin","rb")
d=pickle.load(fo)
r=int(input("enter roll no. to search the student name"))
def search(r):
for key in d:
if key==r:
print("the name of roll no.",key,"is", d[key])
if (r not in d):
print ("this roll no. does not exist")
break
search (roll)
fo.close()
OUTPUT

5. Create a binary file with roll no, name


and marks. Input a Roll no. and update
the marks
import pickle
f=open('student.dat','wb')
while True:
rn=int(input("Enter roll no.:"))
name=input("Enter name:")
marks=int(input("enter marks:"))
l=[rn,name,marks]
rec.append(l)
ch=input("Want to enter more?")
if ch in 'nN':
break
pickle.dump(rec,f)
print("The student details are",rec)
f.close()

f=open('Student.dat','rb')#rec=[[1,'priya',50],[2,'preeti',60]]
found=0
try:
while True:
rec=pickle.load(f)
srn=int(input("Enter the new marks:"))
i[2]=smks
print("The updated record of the student is:",1)
found=1
break
except:
f.close()
if found==0:
print("No such record")

OUTPUT

6. Write a random number generator that


generates random numbers between 1
and 6 (Simulates a dice)
def random():
import random
s=random.randint(1,6)
return s

while True:
ch=int(input("Enter 1 to Roll the dice and any other key to exit..."))
if ch==1:
print('Dice:',random())
else:
print("Game Over")
break

OUTPUT

7. Write a Python Program to implement


a stack using list
stack=[]
def push():
element=input("Enter the element:")
stack.append(element)
print(stack)

def pop_element():
if not stack:
print("stack is empty!")
else:
e=stack.pop()
print("removed element:",e)
print(stack)

while True:
print("select the operation 1.push 2.pop 3.quit")
choice = int(input())
if choice==1:
push()
elif choice==2:
pop_element()
elif choice==3:
break
else:
print("Enter the correct operation!")
OUTPUT

You might also like