Q. Write a method in Python to read lines from a text file DIARY.TXT and display those lines which start with the alphabet 'P'.


Answer =

 

def display ():
  file = open ('DIARY.txt', 'r')
  line = file.readline ()
  while line :
    if line[ 0 ] == 'P' :
      print (line)
    line = file.readline ()
  file.close()


2 Comments

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

Post a Comment

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

Previous Post Next Post