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)

 

2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. this is wrong please correct the program

    ReplyDelete
  2. the answer is
    f=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()

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post