Strings and text · Python exercise
Read a line of text and count whitespace-separated words, including a blank-line case.
Read one line of text and print the number of words. Words are separated by any amount of whitespace. A blank line contains zero words.
Example 1
Input
Python is fun
Output
3
Example 2
Input
hello world
Output
2
How testing works
Your code runs once per test case with that case's standard input. Output is compared after normalising trailing spaces and blank lines at the end. Use input() without a prompt when the exercise expects clean output.
Loading editor…
Press Run tests to execute your code against every input case. Python runs in a Web Worker in your browser.