Day 1Count the Words

    Very easystringssplit

    Write count_words(text) that returns how many words are in text.

    Words are separated by spaces. There may be extra spaces at the start, at the end or between words.

    Examples

    Example 1
    >>> count_words("Python is fun")
    3
    Example 2
    >>> count_words("  hello   world  ")
    2

    Good to know

    • An empty string, or one with only spaces, has 0 words.

    Run examples checks the 2 examples above. Submit runs all 6 tests, including hidden edge cases, and marks the challenge solved.

    solution.py
    Loading Python…

    Test results show up here

    Write count_words in the editor, then run the examples. Use print() freely: its output is shown for each test.