Jul-25-2022, 03:31 PM
As with most things, there's more than one way to do this.
One way to count the number of 'words' from a input, is to convert said into a list, which is what I think that you are attempting with...
This code...
One way to count the number of 'words' from a input, is to convert said into a list, which is what I think that you are attempting with...
words = len(Text.split())I would go one stage further and create a list object with which to work. Also, you've not specified a split separator.
This code...
text_input = input("Enter you text: ") list_input = text_input.split(' ') words = len(list_input) print(f"Your input contains {words} words.")... creates a list object from the user input and then simply outputs the length of that list as the number of words contained therein. What constitutes a 'word' is open to interpretation, but as a basic concept, this may be of help to you.
Sig:
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein