Count the words
Read a line of text and print how many words it has. A word is a run of characters other than spaces; words can be separated by one or more spaces, and the line may start or end with spaces.
Input
One line of up to 1000 characters. It has at least one word.
Output
The number of words.
The input is read for you. The starter code puts it in variables; write your code under Your code here and print the answer. Changed the code already? Reset () brings the starter back.
Example 1
Input
the quick brown fox
Output
4
Why:
Four words, one space between each.
Example 2
Input
hello world
Output
2
Why:
Extra spaces do not make extra words.
Hints
Was this a good challenge?
- Solved by
- 0
- Submissions
- 0
- Accepted
- –