wordcount.py


SUBMITTED BY: Guest

DATE: Sept. 13, 2014, 3:56 a.m.

FORMAT: Python

SIZE: 515 Bytes

HITS: 801

  1. import string # If you don't then write down the whole list of strings a-zA-Z
  2. count = 0
  3. try:
  4. # Counting user input is too much easy
  5. fname = open(raw_input("Enter File name : ")).read()
  6. # Warning, len(fname) cannot be used.
  7. # Because it also counts all those spaces.
  8. except IOError:
  9. print"File not found!"
  10. else:
  11. for i in fname:
  12. if i in string.ascii_letters: # if i in a-zA-Z
  13. count +=1
  14. print"Word Count is : %s" % count

comments powered by Disqus