Count the words on a line. Words are separated by one or more spaces.
Input
A single line of text.
Output
The number of whitespace-separated words.
Count the words on a line. Words are separated by one or more spaces.
A single line of text.
The number of whitespace-separated words.
Example 1
the quick brown fox
4
Four words.
Example 2
hello
1
One word.
Example 3
a b c
3
Repeated spaces still separate just three words.
Splitting the line on whitespace gives you the list of words — its length is the answer.
Most languages ignore leading, trailing and repeated spaces when splitting on whitespace.
Split the line on runs of whitespace and count the resulting words.
print(len(input().split()))
Tell us what needs to change, who it affects and any important deadline. We will review the context and reply with useful next questions.