Q. Write a method in python to read the content from a text file diary.txt line by line and display the same on screen.


Answer =



file = open("diary.txt", "r")

print (file.read())

3 Comments

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

  1. no, it has said to read line-by-line.
    so correct will be:

    file = open("diary.txt", "r")
    for line in file:
    print(line)

    ReplyDelete
    Replies
    1. Have you tried in your PC, because answer is wrong.

      Delete
  2. This program is wrong as it says to rwad line by line it shuold be

    file=open("diary.txt", "r")
    while str:
    str=file.readline()
    print(str,end= ' ')
    file.close()

    ReplyDelete

Post a Comment

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

Previous Post Next Post