Advertisements
Advertisements
Question
Write a program to input any string and find number of words in the string.
Code Writing
Advertisements
Solution
Use split() to divide the string into words and len() to count them.
s = input("Enter any string: ")
words = s.split()
print("Number of words =", len(words))
shaalaa.com
Is there an error in this question or solution?
