PYTHON - DFH | FUNCTION TO DISPLAY NUMBER OF LINES STARTING WITH CHARACTER 'A'.

Write a function in python to count the number of lines in a text file ‘STORY.TXT’ which is starting with an alphabet ‘A’ 

def COUNTLINES():
    file=open(r'D:\Stories\BestFriend.txt','r')
    lines = file.readlines()
    count=0
    for w in lines:
        if w[0]=="A" or w[0]=="a":
            count=count+1
            print(w)
    print("Total lines",count)
    file.close()


1 comment:

Post your comments

Powered by Blogger.