Paint cost | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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))

23rd Mar 2022, 11:33 PM
Earl
Earl - avatar
9 Answers
+ 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.
24th Mar 2022, 7:42 PM
Simon Sauter
Simon Sauter - avatar
+ 3
What exactly do you not like?
23rd Mar 2022, 11:57 PM
Solo
Solo - avatar
+ 3
Describe the task.
24th Mar 2022, 12:07 AM
Solo
Solo - avatar
+ 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.
27th Mar 2022, 8:08 PM
Simon Sauter
Simon Sauter - avatar
+ 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?
24th Mar 2022, 7:26 PM
Lisa
Lisa - avatar
0
When I submit the upper, I failed in 1st test and I don't know why..
24th Mar 2022, 12:02 AM
Earl
Earl - avatar
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.
24th Mar 2022, 6:50 PM
Simon Sauter
Simon Sauter - avatar
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().
24th Mar 2022, 7:31 PM
Simon Sauter
Simon Sauter - avatar
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.
24th Mar 2022, 10:57 PM
Earl
Earl - avatar