हिंदी

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

Advertisements
Advertisements

प्रश्न

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

कोड लेखन
Advertisements

उत्तर

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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 1: Review of Phython - EXERCISE [पृष्ठ २७]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
अध्याय 1 Review of Phython
EXERCISE | Q 24. | पृष्ठ २७
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×