new to python here. I am trying to write a program that calculate the average word length in a sentence and I have to do it using the .split command. btw im using python 3.2
You might want to filter out punctuation as well as zero-length words.
>>> sentence = input("Please enter a sentence: ")
Filter out punctuation that doesn't count. You can add more to the string of punctuation if you want:
>>> filtered = ''.join(filter(lambda x: x not in '".,;!-', sentence))
Split into words, and remove words that are zero length:
>>> words = [word for word in filtered.split() if word]
And calculate:
>>> avg = sum(map(len, words))/len(words)
>>> print(avg)
3.923076923076923