+ 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

10th Aug 2021, 2:39 PM
Rambo
9 Answers
+ 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()
10th Aug 2021, 2:55 PM
Lothar
Lothar - avatar
+ 5
Rambo , it would be very helpful if you could post also the complete task description, the tutorial name and the lesson number. thanks!
10th Aug 2021, 2:46 PM
Lothar
Lothar - avatar
+ 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.
11th Aug 2021, 6:11 AM
Lothar
Lothar - avatar
+ 3
Will u explain more
10th Aug 2021, 2:46 PM
Pariket Thakur
Pariket Thakur - avatar
10th Aug 2021, 2:49 PM
Rambo
+ 2
HrCoder Lothar Thank you very much I got it.. Here's the updated code https://code.sololearn.com/cb6S9DeM9QXt/?ref=app
10th Aug 2021, 3:04 PM
Rambo
+ 2
Lothar Oh gosh, my bad. I've modified it. Thanks for the correction.
11th Aug 2021, 6:24 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Rambo try to use library import math
10th Aug 2021, 2:57 PM
Pariket Thakur
Pariket Thakur - avatar
+ 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
10th Aug 2021, 6:43 PM
Calvin Thomas
Calvin Thomas - avatar