0

Average Word Length, help? (Python)

from functools import reduce import string text = input() for word in text.split(): for char in word: if char in list(string.punctuation): text.replace(char, '') words = text.split() charCount = reduce(lambda x, y: x + y, [len(word) for word in words]) wordCount = len(words) avg = round(charCount / wordCount) print(avg)

8th May 2021, 6:42 PM
Yahel
Yahel - avatar
2 Antworten
0
Mirielle look at the title. My task is to get text and printout the average length of the words in the text. That task is from the codecoach and I dont know why it failed in 2 cases..
8th May 2021, 6:51 PM
Yahel
Yahel - avatar