OMSAKTHI
G B PUBLIC SCHOOL
CLASS XII COMPUTER SCIENCE
MIDTERM LAB EXAM PROGRAMS
1. PROGRAM TO READ A TEXT FILE AND DISPLAY THE NUMBER OF OWELS/CONSONANTS/LOWER
CASE/ UPPER CASE CHARACTERS.
Program:
file=open("[Link]","r")
content=[Link]()
vowels=0
consonants=0
lowercase=0
uppercase=0
for ch in content:
if([Link]()):
lowercase+=1
elif([Link]()):
uppercase+=1
ch=[Link]()
if(ch in['a','e','i','o','u']):
vowels+=1
else:
consonants+=1
[Link]()
print("voweles are:",vowels)
print("consonants are:",consonants)
print("lower_case_letters are:",lowercase)
print("upper_case_letters are:",uppercase)
2. PROGRAM TO READ A TEXT FILE LINE BY LINE AND DISPLAY EACH WORD SEPARATED BY '#'
Program:
f=open("[Link]",'r')
Contents=[Link]()
for line in Contents:
words=[Link]()
for i in words:
print(i+'#',end=' ')
print("")
[Link] ()
3. PROGRAM TO CREATE AND DISPLAY ALL RECORDS IN BINARY FILE
Program:
import pickle
def Write():
f=open("[Link]", 'ab')
D={}
n=int(input("Enter how many Employees' details you want to store"))
for i in range(n):
D['Emp_No']=int(input("Enter the Employee Number:"))
D['Emp_Name']=input("Enter the Employee Name:")
D['Salary']=int(input("Enter the Employee Salary:"))
[Link](D,f)
[Link]()
def Read():
f=open("[Link]",'rb')
try:
while True:
S=[Link](f)
print(S)
except:
[Link]()
Write()
Read()
4. PROGRAM TO CREATE AND SEARCH RECORDS IN BINARY FILE
import pickle
def Create():
F=open("[Link]",'ab')
opt='y'
while opt=='y':
Roll_No=int(input('Enter roll number:'))
Name=input("Enter Name:")
L=[Roll_No,Name]
[Link](L,F)
opt=input("Do you want to add another student detail(y/n)")
F. close ()
def Search():
F=open("[Link]",'rb')
no=int(input("Enter [Link] of student to search:"))
found=0
try:
while True:
S=[Link](F)
if S[0]==no:
print("The searched [Link] is found and Details are:",S)
found=l
break
except:
[Link] ()
if found==0:
print("The Searched [Link] is not found")
#Main Program
Create()
Search()