def fileToString(filename):
    myFile = open(filename, "r")
    myText = ""
    for ch in myFile:
        myText = myText + ch
    return myText

def countVowels(text):
    vcount = 0
    vowels = ['a','e','i','o','u']
    for letter in text:
        if (letter in vowels):
            vcount = vcount + 1
    return vcount

write a program to calculate the following statistics from a text file:

Number of Vowels
Number of Consonants
Number of Words
Number of Sentences
Number of Questions
Average Word length
Average Sentence length

The program should give the user an option to display the statistics on screen and/or write them to a separate output file. Use functions to calculate each of the above and store the functions in a separate file, for importing into your main program. Include the following in your documentation:

Introduction
Flowchart
Pseudocode
Commented Code
Testing
Conclusion

Recommended Answers

All 5 Replies

Sorry. We don't do your homework for you. Make an effort and we can help you debug your work. Do read this site's terms of service (TOS) in regard to this issue.

Something like:
Read through every character in the text file
If the character is a vowel add one to the vowel count
If the character is a consonant add one to the consonant count
If the character is a space add one to the word count
If the character is a period or '?' or '!' add one to the sentence count
If the character is a questionmark add one to the question counter

Average word length is approximately text-length/word-count
Average sentence length is approximately text-length/sentence-count

@ Rubberman, Hey man, take it easy lad, Id am new to programming, only looking for help from pros so chilled out if you cant help.... the site site that ask me to pay money if i want quick responds, Anyway if you dont feel like sharing your knowlegde pls shut d f**k up.

@HiHe..Thanks for the tips, still cant get it to work.

Please tone down. Our rules clearly state that you should show your effort, which is clearly lacking in your OP. Show YOUR code, and clearly explain what parts you are having difficulty with.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.