129k views
5 votes
How do you find the average length of words in a sentence with Python?

1 Answer

2 votes

Answer:

split() wordCount = len(words) # start with zero characters ch = 0 for word in words: # add up characters ch += len(word) avg = ch / wordCount if avg == 1: print "In the sentence ", s , ", the average word length is", avg, "letter." else: print "In the sentence ", s , ", the average word length is", avg, "letters.

User Vivek Gupta
by
5.4k points