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?
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.
+ 1
《 Nicko12 》, thank you for the response! I did solve the problem now.