Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+3 votes

How do you do the loop for in question 4?

I am not sure how to get the loop to find length for each word?

asked in CSC201 Spring 2021 by (1 point)

1 Answer

+3 votes

First, use "split" to get a list of the words in the sentence.

Make a for loop to go through each word in the list. You also need set a variable to count the total length of all the words by adding it to itself and the length of the word (using len()). You also need another variable to count the numbers of words.


`totalLength=totalLength + len(word)`

Then, the average length will be the total length /numbers of words

answered by (1 point)

Thank you!!