Python program to Count Total Number of Words in a String

str1=input("Please Enter a string \n")
tot=1;
for i in range(len(str1)):
    if(str1[i]==' ' or str1 == '/n' or str1 == '\t'):
        tot=tot+1
print("Total number of words in the given string= ",tot)

OUTPUT:

Please Enter a string
Python programming language
Total number of words in the given string= 3

Sharing Is Caring

Leave a Comment