Q. Write a program to print following type of statics for the given file:
16824 line in the file
438 empty lines
53.7 average characters per line
65.9 average characters per non – empty line
Answer =
file = open("portalexpress.txt","r") text = file.readlines() file.close() for i in text: print (i)
this is wrong please correct the program
ReplyDeletethe answer is
ReplyDeletef=open("sarojinipoem.txt","r")
s=f.read()
lines=s.count("\n")
print("no of lines=",lines+1)
l=len(s)
f.seek(0)
s=f.readlines()
empty=s.count("\n")
print("no of empty lines=",empty)
print("avg chars per line=",l/lines)
print("avg chars per non empty line=",l/(lines-empty))
f.close()
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )