+ 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
4 Antworten
+ 4
First you have to remove all punctuation.
Last you have to round up to the next integer.
+ 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
+ 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)))