Your program should calculate and output (to the screen) the following information about the file of text:
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 periods in the file.
4. The number of characters in the file which are neither blanks nor newline characters, including all punctuation. (Be careful of red herrings…)
5. The number of words in the file. Note: there will not be any “cheap-tricks” regarding this in the input file. Words will not be hyphenated over two lines.
Hi all, just a little confused on how to approach parts of this program. In the part that I have written so far, I can calculate the number of lines and the number of blank lines. When I hit part 3, I get a little confused. Currently, "periods" always returns as 0. Here is what I have so far:
lines = 0 blanklines = 0 periods = 0 myFile = open("inn.txt", "r") for line in myFile: lines +=1 if line == ('\n'): blanklines +=1 for char in myFile: if char == '.': periods +=1 print "The total number of lines in the file is",lines print "The total number blank lines in the file is", blanklines print "The total number of periods in the file is", periods
Note that we are not allowed to access built in python string functions besides len.