954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Can you please help me write this word count program in another way

Word Count. A Common Utility On Unix/linux Systems Is A Small Program Called "wc." This Program Analyzes A File To Determine The Number Of Lines, Words, And Characters Contained Therein. Write A Version Of Wc. The Program Should Accept A File Name As Input And Than Print Three Numbers Showing The Count Of Lines, Words, And Characters In The File. I use Gettysburg address.

#The number of lines, and the number of words.


import string


def main():
    data = raw_input("Enter the path and name of your ")
    infile = file(data, 'r')
    data_file = infile.read()
    number_of_characters = len(data_file)
    print "The number of characters in your text is", number_of_characters

    list_of_words = string.split(data_file)
    number_of_words = len(list_of_words)
    print "The number of words in your text is", number_of_words
    infile.close()

    secondfile = file(data, 'r')
    line_of_text = secondfile.readlines()
    print line_of_text
    number_of_lines = len(lines_of_text)
    print "The number of lines in your text is"  ,  number_of_lines

    infile.close()

main()
Attachments gettysburg_address.doc (20KB)
butterflyTee
Light Poster
43 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You