Do it on paper first. Then tell the computer how you did it.
Example:
I like food. Pizza is my favorite! What food do you like? |
The assignment wants me to keep track of two pieces of information:
number of sentances
average number of words per sentance
To calculate that second one, I also need to know
number of words in each sentance
So I start counting.
"I" -- one word, not end of sentance (no . ! or ?, just whitespace)
"like" -- two words, not EOS
"food." -- three words, EOS (found a .)
So far: one sentance, and 3 wps / 1 sentance --> 3 wps on average
Repeat until done.
You can either keep an array to remember how many words each sentance has and calculate the average at the end...
Or you can apply a little math and calculate the average on the fly:
Given
7 3 9 5
The average is
7 / 1 = 7
7+3 / 2 = 5
5+9 / 2 = 7
7+5 / 2 = 6
6
Notice how we calculated the average on the fly?
Hope this helps.