DML School of Technology
Menu

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

CallExpectedYours
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

Next challenge · All challenges

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.