hello I have to calculate the arithmetic mean in the text (the number of letters divided by the number of sentences). The problem is that when counting letters, it also counts spaces and the result is spooky. How can I easily exclude joints from counting?
Text = input("give text: ")
characters = len(Text)
words = len(Text.split())
a = characters
b = words
division = a/b
print("words in this text hawe ", division, "characters")
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...
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.
This example joins all the words without spaces
words = input("Enter text: ").split()
print(len(''.join(words) / len(words))
This example sums the lengths of each word.
words = input("Enter text: ").split()
print(sum(map(len, words)) / len(words))