0

Average word length

I tried solving average word length code coach problem..but it's passing 3/5 test cases...Can anybody please guide me out..This is my code... https://code.sololearn.com/cRJKM7Yw6a96/?ref=app

27th Mar 2022, 12:03 PM
Suha Akrami
Suha Akrami - avatar
4 Respostas
+ 5
Ervis Meta - SoloHelper , since this challenge has to run with code coach, no extra output can be done except the required value. the task also requires that all punctuation has to be removed from input text, and the result has to be rounded up to the nearest whole number. so your code could not pass the test cases. Suha Akrami , just for your information a code that respects entry level knowledge and has a good readabilty: https://code.sololearn.com/cpXWtiKEudTK/?ref=app
27th Mar 2022, 5:06 PM
Lothar
Lothar - avatar
+ 3
Suha Akrami Use ceil instead of round And get words length without special characters import re from math import ceil #Average Word length statement = (input()) count = 0 char = 0 for words in statement.split(): if words.isalpha: count += 1 char += len(re.sub('[^a-zA-Z0-9\n\.]', '', words)) average = char / count print (ceil(average) )
27th Mar 2022, 12:17 PM
A͢J
A͢J - avatar
+ 2
Thanks AJ..tried out your solution ....It worked
27th Mar 2022, 3:06 PM
Suha Akrami
Suha Akrami - avatar
0
Why to suffer, try this: e = list(map(len,input('Enter separating with spaces: ').split())) print('Average: %s'%(sum(e)/len(e)))
27th Mar 2022, 12:18 PM
Ervis Meta
Ervis Meta - avatar