English

Write a program to input any string and find number of words in the string.

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?
Chapter 1: Review of Phython - EXERCISE [Page 27]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 1 Review of Phython
EXERCISE | Q 24. | Page 27
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×