+ 2
Paint cost
Hello, Can you tell me what the problem is? Thank you in advance! 😁 x=int(input()) cost=(40+(5*x))*1.1 import math print(math.ceil(cost))
9 Antworten
+ 7
Okay. I figured out what is going on (although I'm not sure why):
The input of case 1 is 2. So with this formula
cost=(40+(5*x))*110/100
cost is 55. Now this formula returns 55.0 in python. So rounding up makes no difference and all you need to do is convert to int.
However when you replace "110/100" with "1.1" there is a precision error resulting in 55.00....01. And rounding that up gives the wrong result.
+ 3
What exactly do you not like?
+ 3
Describe the task.
+ 3
I sent in a bug report detailing the issue. Floating point precision issues should not be a stumbling block in an "easy" code coach.
+ 2
I don't think rounding up is the problem. But when having rounded up, we still need to make sure that we output as integer.
I had solved it with
int(ceil(result))
It might be coincidence that in the Python version round() works?
0
When I submit the upper, I failed in 1st test and I don't know why..
0
There's a mistake in that particular Code Coach. The task description asks for the result to be rounded *up*. However, to pass the test cases you actually have to use regular rounding.
0
Lisa weird. When I use math.ceil() the output for case 1 is 56, but the expected output is 55. It works when I use round().
0
Thank you, all! I am not sure what the difference between 110/100 and 1.1 but when I replace 1.1 with 110/100, it is solved.