Counter - sentences += line.count('.') + line.count('!') +...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
print '%26s %5s %15s'% ('Simple:Nonsimple','|','Average Words') print '%25s %6s %15s'% ('Sentence Ratio','|','per Sentence:') print '-'*50 def Counter(filename): lines = sentences = words = 0 for line in open(filename,'r'): lines += 1 if line.startswith('\n'): blanklines += 1 else: # assumes certain stop punctuation and counts to calculate sentences.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: sentences += line.count('.') + line.count('!') + line.count('?') # word total count words += len(line.split()) ratio = float(words)/float(sentences) print '%1s %30.2f'% (filename,ratio) Counter('text1.txt') Counter('text2.txt') Counter('text3.txt')...
View Full Document

Ask a homework question - tutors are online