Ok here is what i need to do.
Read in a text file and calculate
1. The total number of lines in the file, including blank lines.
2. The number of blank lines in the file.
3. The number of sentences in the file of text. You may assume that sentences must end with a period, a question mark, or an exclamation point.
4. The number of words in the file. (Think about how you can determine when a word ends.)
5. The number of non-blank characters in the file, including punctuation.
myInFile = open("inn.txt", "r")
TotalLines = 0
BlankLines = 0
Words = 0
for ch in myInFile:
TotalLines = TotalLines + 1
InLine = myInFile.readline()
if (InLine == "
BlankLines = BlankLines + 1
print "Total Words", Words
print "Total Lines", TotalLines
print "Total Blank Lines", BlankLines
That is what i have so far but doing for ch in myInFile doesnt look at each character and i cant figure out how to. Also shouldn't if (InLine == "
"): give me the total number of blank lines? It doesnt seem to be working. I guess until I can figure out how to look at the characters in each line I'm kind of at a dead end. Any help would be appriciated. If someone could help my get started here and tell me if i am even close to being on the right track I would appriciate it.
0 · ·