+ 4
Average word length (need help)[Solved]
Kindly help me to find what's wrong with my code It passes 2 out 5 test here's the challenge https://www.sololearn.com/coach/73?ref=app And Here is my python code https://code.sololearn.com/cb6S9DeM9QXt/?ref=app
9 odpowiedzi
+ 9
Rambo ,
the task description says:
Output Format:
A number representing the average length of each word, rounded up to the nearest whole number.
rounding up means that you have to use math.ceiling() for rounding not the regular round()
+ 5
Rambo ,
it would be very helpful if you could post also the complete task description, the tutorial name and the lesson number.
thanks!
+ 5
Calvin Thomas , (average word length)
> It's the simple things in life that work! <
the last version from you does not work properly. giving input of: "aaaa bbbb cccc", the output is 12 ??? but should be 4.
+ 3
Will u explain more
+ 2
+ 2
HrCoder
Lothar
Thank you very much I got it..
Here's the updated code
https://code.sololearn.com/cb6S9DeM9QXt/?ref=app
+ 2
Lothar Oh gosh, my bad. I've modified it. Thanks for the correction.
+ 1
Rambo try to use library
import math
+ 1
Rambo Here's a simpler solution:
[EDITED]
var = "".join(x for x in input() if x == " " or x.isalpha())
avg = len(var) / len(var.split())
print(int(avg) + (int(avg) < avg))
# Hope this helps