Q. Write a function in Python to count the number of lines in a text file 'STORY.TXT' which are starting with the alphabet 'A'.
Answer =
def COUNTLINES () : file = open ('STORY.TXT', 'r') lines = file.readlines () count=0 for w in lines : if w[0] == "A" or w[0] == "a" : count = count + 1 print ("Total lines : ", count) file.close()
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )