Stretch, Strings
Count the words
The task
Count the words in a piece of text. There may be extra spaces at the start, at the end or between words, and the text may be empty.
Write a function called count_words.
Tests
| Call | Expected | Yours |
|---|---|---|
count_words('the cat sat') |
3 |
not run |
count_words(' spaced out ') |
2 |
not run |
count_words('') |
0 |
not run |
count_words('one') |
1 |
not run |
solution.py
Tab indents. To leave the editor, press Escape, then Tab.
Output
Run prints what your code prints. Run the tests to check your function.