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
4 Answers
+ 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
+ 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) )
+ 2
Thanks AJ..tried out your solution ....It worked
0
Why to suffer, try this:
e = list(map(len,input('Enter separating with spaces: ').split()))
print('Average: %s'%(sum(e)/len(e)))