Program-1: Source Code
Program-1: Source Code
This program specifically performs splitting of file data and insert “#” in the
end of every word.
SOURCE CODE My
self.txt
def word_as():
file=open(r'E:\My self.txt',"r")
lines=file.readlines()
words=line.split()
print(word+"#",end="")
print("")
file.close()
#main program
word_as()
1
OUTPUT
2
Program-2
This program counts Total number of consonants ,vowels , Uppercases and
Lowercases.
def cnt():
f=open(r'E:\Sample Input.txt',"r")
cont=f.read()
print(cnt)
v=0
cons=0
l_c_l=0
u_c_l=0
for ch in cont:
if (ch.islower()):
l_c_l+=1
elif(ch.isupper()):
u_c_l+=1
ch=ch.lower()
if( ch in ['a','e','i','o','u']):
v+=1
3
'h','j','k','l','m',
'n','p','q','r','s',
't','v','w','x','y','z']):
cons+=1
f.close()
#main program
cnt()
OUTPUT
4
Program-3
This program Remove all the line that contain character ‘a’ and write
another file.
myfile=open("E:\My self.txt","r")
line=" "
lst=[]
while line:
line=myfile.readline()
if "a" in line:
lst=line
myfile.close()
fobj=open("E:\SSd.txt","a")
fobj.write(lst)
fobj.close()
5
OUTPUT
Ssd.txt
6
Program-4
This program create binary file with name and roll number. If not found display
appropriate message.
import pickle
import sys
dict={}
def write_in_file():
file=open("E:\\Mukesh.dat","ab") #a-append,b-binary
for i in range(no):
file.close()
def display():
file=open("E:\\Mukesh.dat","rb") #r-read,b-binary
try:
7
while True:
print(stud)
except EOFError:
pass
file.close()
def search():
file=open("E:\\Mukesh.dat","rb") #r-read,b-binary
found=0
try:
while True:
if data["roll"]==r:
print(data)
found=1
break
except EOFError:
pass
if found==0:
file.close()
8
while True:
if ch==1:
write_in_file()
if ch==2:
display()
if ch==3:
search()
if ch==4:
sys.exit()
OUTPUT
9
10
Program-5
This program create a binary file with name ,roll number and marks input marks
and update the marks.
import pickle
student_data={}
file=open("D:\\stud_u.dat","ab")
for i in range(no_of_students):
pickle.dump(student_data,file)
student_data={}
file.close()
11
#reading the file logic
file=open("D:\\stud_u.dat","rb")
try:
while True:
student_data=pickle.load(file)
print(student_data)
except EOFError:
file.close()
found=False
file=open("D:\\stud_u.dat","rb+")
try:
while True:
pos=file.tell()
student_data=pickle.load(file)
if(student_data["RollNo"]==roll_no):
#print(student_data["Name"]
file.seek(pos)
pickle.dump(student_data,file)
found=True
except EOFError:
if(found==False):
12
print("Roll no not found please try again")
else:
file.close()
#Displaying logic
file=open("D:\\stud_u.dat","rb")
try:
while True:
student_data=pickle.load(file)
print(student_data)
except EOFError:
file.close()
13
OUTPUT
14
Program-6
This program generate random number between 1 and 6 ( simulates a dice)
SOURCE CODE
import random
str1=" "
while Mess=="Y":
die=random.randint(1,6)
print(die)
OUTPUT
15
Program-7
This program is a CSV file by entering user-Id and password , read and search the
password for given user-Id.
SOURCE CODE
import csv
def register():
writer = csv.writer(f,delimiter=",")
if password == password2:
writer.writerow([email,password])
print("Registrartion is succesfull!")
else:
def login():
with open("users.csv",mode='r') as f:
reader = csv.reader(f,delimiter=",")
if row ==[email,password]:
16
return True
return False
register()
login()
OUTPUT
17