73.9k views
5 votes
Write a function def countWords(stri ng) that returns a count of all words in the string string. Words are separated by spac For example, countWords ("Mary had a little lamb") should return 5.

1 Answer

5 votes

Answer:

def w_count(s):

return(len(s.split()))

st=input('Enter a string:')

print("Number of words in given string=",w_count(st))

Step-by-step explanation:

Write a function def countWords(stri ng) that returns a count of all words in the-example-1
Write a function def countWords(stri ng) that returns a count of all words in the-example-2
User Stagg
by
6.0k points