Trying to write a simple program that calculates the average length of words used in a sentence. My issue is that the spaces are taken into an account when counting characters, and that gives higher number for average. The replace("","") function had to eliminate spaces form the input, but it does not seem to work. Any ideas? Thank you.
def main(): sentence = input("Enter text: ") words = len(sentence.split()) chars = len(sentence.replace("","")) avg = chars / words print("Your average word length is:", round(avg)) main()