okcopy - # word total count words += len(line.split()) ns +=

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

View Full Document Right Arrow Icon
print '%26s %5s %15s'% ('Nonsimple:Simple','|','Average Words') print '%25s %6s %15s'% ('Sentence Ratio','|','per Sentence:') print '-'*50 def Counter(filename): lines = sentences = words = ns = 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. sentences += line.count('.') + line.count('!') + line.count('?')
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: # word total count words += len(line.split()) ns += line.count('and')+ line.count('but')+ line.count('because') average = float(words)/float(sentences) ss = (float(sentences)-float(ns)) print '%1s %5i %1s %1i %11s %8.2f'% (filename,ns,':',ss,'|',average) Counter('text1.txt') Counter('text2.txt') Counter('text3.txt')...
View Full Document

This note was uploaded on 09/06/2009 for the course LING 571 taught by Professor Staff during the Fall '08 term at San Diego State.

Ask a homework question - tutors are online