Not able to pass the all test cases | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Not able to pass the all test cases

I am trying to solve the average of the string but all testcases are not passing Can anyone help me where I am going wrong? https://code.sololearn.com/cBCbNYNn6X5o/?ref=app

18th Jun 2021, 7:09 AM
Pankaj Rajani
Pankaj Rajani - avatar
4 Answers
+ 4
First you have to remove all punctuation. Last you have to round up to the next integer.
18th Jun 2021, 8:16 AM
David Ashton
David Ashton - avatar
+ 2
Thanks David Ashton The future is now thanks to science[LESS ACTIVE] import string import math str=input() lst=str.split() count=0 for i in str: if i== " " or i in string.punctuation: continue else: count=count+1 print(math.ceil(count/len(lst))) For helping to fix it
18th Jun 2021, 11:57 AM
Pankaj Rajani
Pankaj Rajani - avatar
+ 2
Nice. I did it this way from math import ceil as ce phrase = "".join(c for c in input() if c.isalpha() or c == " ") words = phrase.split() print(ce(sum(len(word) for word in words) / len(words)))
18th Jun 2021, 10:18 PM
David Ashton
David Ashton - avatar
18th Jun 2021, 7:18 AM
The future is now thanks to science
The future is now thanks to science - avatar