Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Reading chars in a text file
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 · ·