-If have a file then it might be possible that this file contain multiple lines.
-so here task is to count the number of line in exist file.
Example-
file contain the following data-
first
second
third
fourth
five
then number of line count is 5
program-
f=open('myfile.txt','w')
f.writelines("first linensecond linenthird linenfourth linenfifth line")
f.close()
#first way
f=open('myfile.txt','r')
count=0
while(f.readline()!=''):
count+=1
print("Number of lines in file is",count)
f.close()
#second way
f=open('myfile.txt','r')
s=f.read()
count=s.count("n")+1
print("Number of lines in file is",count)
f.close()
Number of lines in file is 5
Number of lines in file is 5