CBSE Class 12 Computer Science
Question 94 of 136
Data File Handling — Question 33
Back to all questionsLet the file "f1.txt" include the following sample text:
Soft whispers of the wind.
A melody in the trees.
Sun-kissed petals dance.
A garden's quiet song.
file_name = 'f1.txt'
line_number = 1
f = open(file_name, 'r')
for line in f:
print("Line", line_number, ":", line.strip())
line_number += 1
f.close()Line 1 : Soft whispers of the wind.
Line 2 : A melody in the trees.
Line 3 : Sun-kissed petals dance.
Line 4 : A garden's quiet song.