logo CodeStepByStep logo

word_count

Language/Type: Python if/else return string cumulative algorithms

Write a function named word_count that accepts a String as its parameter and returns the number of words in the String. A word is a sequence of one or more nonspace characters (any character other than ' '). For example, the call word_count("hello") should return 1, the call word_count("how are you?") should return 3, the call word_count(" this   string has     wide     spaces   ") should return 5, and the call word_count(" ") should return 0.

Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.