Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- import string
- x = raw_input("Enter filename (including extension) here: ")
- infile = open(x, 'r')
- myfile = infile.read()
- mylist = string.split(myfile)
- count_words = 0
- count_letters = 0
- for i in mylist:
- count_words = count_words + 1
- for j in range (len(mylist[i])):
- count_letters = count_letters + j
- print "*** Opening filename", x, "***"
- print "The file contains", count_words, "words."
- print "The average word length is %0.2f letter(s)." %(float(count_words)/count_letters)
- infile = close(x, 'r')
- print "*** Closing filename", x, "***"
- print "Done!"
- main()
Add Comment
Please, Sign In to add comment