am trying to create a python code that counts words,vowels,consonats,upperand lower case letter,and the frequency which has the option like Do you want to enter the text via the keyboard? Do you want to read in the text from a file?
here is how i got but idont if am heading the right way.
sentence = input("Enter a sentence: ")

import os, sys
def fileCount(filename):
if isinstance(filename, basestring) and os.path.isfile(filename):
txt = open(filename).read
linecount = txt.count('\n')
numUpperCase = 0
numVowel = 0
numChars = 0
sentence = ""
for character in sentence
if(character == ' '):
if((character >= 'A') and (character <= 'Z')):
numUpperCase += 1
if((character =='a'),(character == 'A'),(character == 'e'),
(character == 'E'),(character == 'i'),(character == 'I'),
(character == 'o'),(character == 'O'),(character == 'u'),
(character == 'U'),(character == 'y'),(character == 'Y')):
numVowel += 1
numChars += 1
print("\nTotal number of UPPERCASE letters: \t%d" %(numUpperCase))
print("Total number of vowels: \t\t%d" %(numVowel))
print("Total number of characters: \t\t%d" %(numChars))

3 Years
Discussion Span
Last Post by pyTony


I'm not entirely sure what your question is.

Perhaps you need to make a list of what you want / need this program to do, that way, you can break it down into simple steps and develop them one by one, making your life easier.

How would you like us to help?


hello this a question that am attempting to answer

Analysis of text is a crucial aspect of many computing applications. The ability to single out words and phrases allows us to look for, for example: themes, sentiment and complexity of language. For example, many on-line games allow players to message each other during the game and twitter users send different messages. Analysis of these messages might reveal a lot about the writers and their experience of the application they are using.
In this part of the assignment you are required to create a programme that looks at sentences of text and carries out an analysis of the words entered.
On running the programme the user should be presented with two options:
Do you want to enter the text via the keyboard?
Do you want to read in the text from a file?
If ‘Option 1 ’ is selected then the user will enter one or more sentences of text, one sentence at a time. The use of an asterisk (*) could indicate the end of the entry. For example they may enter:

The cat sat on the mat.*

The program should then report back some basic analysis of this text:
Number of sentences entered = 1 Number of vowels = 6 Number of consonants =11 Number of upper case letters = 1 Number of lower case letters =16 The frequency of individual letters = ?
If ‘Option 2’ is selected then a file of pre-written text is opened, read and a similar analysis is carried out and displayed on the console. In addition a file of “long words” is created as part of the application and saved in the current directory i.e. any words longer than 7 characters.
Completing the implementation of Option 2 in addition to Option 1 will allow a higher grade to be attained (2:1 or above).
For those who are looking for an even greater challenge, a more enhanced solution to the problem might be for example:
• To assess the ‘sentiment’ or ‘mood’ of the text. How might this be done?
Enhanced additions to the basic requirements set out above will allow for greater achievement - but you can still get a good grade by completing the basic requirements of Options 1 and 2.
In addition, you should devise a test plan for testing your program and thoroughly test your program using black box and white box testing techniques. The test plan and results and evidence of testing form part of the submission (see below for details).


Why are you assigning file's read method to variable txt, that is deceptive naming? And you are not using the method anywhere.

txt = open(filename).read
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.