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

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.