+ 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
11 Antworten
+ 4
import math
math.ceil(x)
+ 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.
+ 2
Please can you write the code let me try it out
+ 2
No, but maybe this works:
round(x + 0.5)
+ 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
+ 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.
+ 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?
+ 1
Okay I get your point.
+ 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
+ 1
Thank you Smith welder.
0
Hello