infile = open("inputex1.txt","r")
line = infile.readline()
print("1 "+line, end="")
i = 2
while line !="" :
line = infile.readline()
print(str(i)+" "+line, end="")
i+=1
infile.close()
the text file is:
Mary had a little lamb,
whose fleece was white as snow.
And everyWhere that Mary went,
The Lamb was sure to go
And yet the output is:
1 Mary had a little lamb,
2 whose fleece was white as snow.
3 And everyWhere that Mary went,
4 The Lamb was sur to go
5
my question is, why does it keep entering the while loop after reaching the fifth line? why is there a 5 in the end?