Question: Write a Python function named count_words (text) that takes a single parameter that is a string and returns the number of words in that string.

Write a Python function named count_words (text) that takes a single parameter that is a string and returns the number of words in that string. For the purpose of this function, a word is any sequence of characters separated by whitespace. A whitespace character is any character in the string string.whitespace. For example, the following code should run without error assert 0count words ("") assert 0count words (" assert 1 =-count words ("hello") assert 1=-count words (" hello ") assert 2count words ("hello world") assert 5count_words ("hello world how are you?") assert 5count words (" hello world how are you?")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
