Guest User

Untitled

a guest
Jul 16th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. def main():
  2. import string
  3. x = raw_input("Enter filename (including extension) here: ")
  4. infile = open(x, 'r')
  5. myfile = infile.read()
  6. mylist = string.split(myfile)
  7. count_words = 0
  8. count_letters = 0
  9. for i in mylist:
  10. count_words = count_words + 1
  11. for j in range (len(mylist[i])):
  12. count_letters = count_letters + j
  13. print "*** Opening filename", x, "***"
  14. print "The file contains", count_words, "words."
  15. print "The average word length is %0.2f letter(s)." %(float(count_words)/count_letters)
  16. infile = close(x, 'r')
  17. print "*** Closing filename", x, "***"
  18. print "Done!"
  19.  
  20. main()
Add Comment
Please, Sign In to add comment