Monday, 8 February 2021

Practical No. 5: WAP in Python to read a text file and print the line or paragraph starting with the letter ‘S’

 








#Practical No. 5- WAP in  python  to read a text file, count and print no. of line

#start from 'S' or 's'


f=open("abc.txt","r")

line=f.readline()

lc=0

while line:

    if line[0]=='s' or line[0]=='S':

        print(line,end="")

        lc=lc+1

    line=f.readline()

f.close()

print("Total number of lines start with 's' or 'S'=",lc)



No comments:

Post a Comment