Q. Write a function in python to count the number of lines in a text file 'STORY.TXT' which is starting with an 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 started with 'A' or 'a'", count)
  file.close()

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post