+ 4

Why where does this logic fail

First I strip a string of punctuations. Then I convert it into a list. Then I convert the list into integers. Finally I calculate the average word length. https://code.sololearn.com/cQ8Xa3q1b80z/?ref=app

14th Jan 2023, 8:37 AM
Gemuh Hans
11 Antworten
+ 4
import math math.ceil(x)
14th Jan 2023, 9:12 AM
JaScript
JaScript - avatar
+ 3
In the task you can see „The average word length is 5.20 letters, rounding it up to the nearest whole numbers results in 6.“ That means ceiling instead rounding is required.
14th Jan 2023, 9:01 AM
JaScript
JaScript - avatar
+ 2
Please can you write the code let me try it out
14th Jan 2023, 9:08 AM
Gemuh Hans
+ 2
No, but maybe this works: round(x + 0.5)
14th Jan 2023, 9:34 AM
JaScript
JaScript - avatar
+ 2
Ok thank you. I think I prefer the other one but this one works just fine too. The issue is it might increase the value in some cases above the required
14th Jan 2023, 9:37 AM
Gemuh Hans
+ 2
The round() function returns a floating point number that is a rounded version of the specified number, with the specified number of decimals. The default number of decimals is 0, meaning that the function will return the nearest integer. Syntax round(number, digits) If the rounding digit is less than 5, round x down to the nearest integer. Otherwise, round x up.
14th Jan 2023, 9:40 AM
JaScript
JaScript - avatar
+ 1
Thank you so much I succeeded in my task and got the xp points. Why question is why rounding give the wrong answer. Can we still use round and specify that rounding should be done up?
14th Jan 2023, 9:26 AM
Gemuh Hans
+ 1
Okay I get your point.
14th Jan 2023, 9:43 AM
Gemuh Hans
+ 1
i looked at your code and left comments there so you can understand https://code.sololearn.com/cPLbU55tv6Pf/?ref=app P. S. I know that you have already completed the task, but maybe others will be interested
15th Jan 2023, 7:18 PM
Smith Welder
Smith Welder - avatar
+ 1
Thank you Smith welder.
15th Jan 2023, 8:36 PM
Gemuh Hans
0
Hello
14th Jan 2023, 9:08 AM
Gemuh Hans