def Count_Total_Words(str1):
total = 1
for i in range(len(str1)):
    if(str1[i] == ' ' or str1 == '\n' or str1 == '\t'):
        total = total + 1
return total

string = input("Please Enter your Own String : ")
leng = Count_Total_Words(string)
print("Total Number of Words in this String = ", leng)

Recommended Answers

That method looks to have flaws.

  1. Doesn't count words. (counts what it counts.)
  2. A double space would throw it off and more.
  3. A very well done app. Read https://github.com/coreutils/coreutils/blob/master/src/wc.c
Jump to Post

All 2 Replies

PS. I didn't add another probable flaw. Also, what did you mean by the comment? (I can see it still.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.