Question: write sentinel logic manipulate strings and lists use a counter and an accumulator It is common in word processing to count the words and characters

write sentinel logic
manipulate strings and lists
use a counter and an accumulator
It is common in word processing to count the words and characters in a group of lines. You've probably used it in Word to make sure your essay was long enough.
The program should accept any number of words on the line of input, delimited by whitespace. Any number of whitespace characters should be treated as one delimiter. See the Strings II slides about "split without an argument".
Note that a "word" is just something surrounded by whitespace. It is NOT just words from the dictionary. As you can see from the sample runs below, any character is allowed as input.
The program counts the number of words and finds the average length of the words. You will need the split method and len function to count the words. Note that it is NOT sufficient to take the length of each string input and add them together. That would count the whitespace also!
Accept input from the user until they press just the enter key by itself. This is your sentinel. Remember input returns an empty string when the user just presses Enter.
To find the total length of all the words in a list, you MUST access them one at a time, no function will give your their total length with one call.
Example: a list like ['the','green', 'house'] has a length of 3(not 13!). To find the length of all the words, you have to process the list elements one at a time, total =0, total =0+3=3, total =3+5=8, total =8+5=13.
To find an average you need an accumulator and a counter. Make sure your code never divides by zero. Format your average to 2 places.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!