← Back to Strings
Question 51
Count The Words
Count The Words
Read one sentence and print three lines about its words: Words: <n>, the number of words; Longest: <word>, the longest word (on a tie keep the earlier one); and Letters: <n>, the total number of characters in all the words together. Split the sentence into a list with sentence.split(), which breaks it at the spaces and returns a list of the words, then get the count with len() and find the other two values with one for loop over the list. Input: one line, at least one word, no prompt.
Expected Output:
Words: 4 Longest: quick Letters: 16
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Strings
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.