0

Average word length problem

import math sentence = input() sentence_split = sentence.split(" ") total = 0 for i in sentence_split: total = total + len(i) ave = total/len(sentence_split) print(math.ceil(ave)) When I try this code, my test case 1 is failed. But when i try to change ave = total/len(sentence_split) to ave = (total-1)/len(sentence_split), the test case 1 passed but the test case 5 failed. Can someone tell me what part of my code is missing or what should i change?

27th Jan 2021, 11:12 AM
Bryan Mago
Bryan Mago - avatar
2 Réponses
+ 4
Remember that it is stated in the problem to remove first the PUNCTUATIONS. The first test case has a question mark in it ('?'). You can remove the punctuation by iterating the string then use conditions. Good Luck.
27th Jan 2021, 11:19 AM
noteve
noteve - avatar
+ 1
《 Nicko12 》, thank you for the response! I did solve the problem now.
27th Jan 2021, 11:33 AM
Bryan Mago
Bryan Mago - avatar