CBSE Class 12 Computer Science Question 96 of 136

Data File Handling — Question 35

Back to all questions
35
Question

Question 35

Write a method in Python to read the content from a text file "DIARY.TXT" line by line and display the same on the screen.

Answer
def diary_content(f):
    myfile = open(f, "r")
    str = " "
    while str:
        str = myfile.readline()
        print(str, end = '')
    myfile.close()

diary_content("DIARY.TXT")