+ 1
How to get round values
I have tried paint cost challenge in code coach But i am getting errors as my output is like 55.0 and expected output is 55 color=int(input()) supplies=40 cost=supplies+(color*5) total=((10/100)*cost)+cost print(total)
17 Answers
+ 6
Guraja Teja Surya Lokesh Kumar
Use math.ceil or add just 0.5 in total and cast with int
print(int(math.ceil(total)))
Or
print (int(total + 0.5))
+ 7
Guraja Teja Surya Lokesh Kumar
Do this
print(int(total))
+ 7
I Am AJ ! ; The result is correct for certain numbers, but not for all:
print(ceil((canv_brush +(colors * onecolor)) / 100 * 110))
print(int(((canv_brush +(colors * onecolor)) / 100 * 110)+0.5))
# when giving input = 14 (or 15,...)
# result with ceil(N) = 122
# result with int(N +0.5) = 121
+ 6
Guraja Teja Surya Lokesh Kumar It says to "round up", so use math.ceil(total)
and don't forget to import math library.
+ 6
I Am AJ ! , you mentioned to use something like that: " ... or add just 0.5 in total and cast with int"
- > but this does not give the same result than using ceil()
▪︎assuming we have a value of 2.3 and try to round this UP:
▪︎math.ceil(2.3) = 3
▪︎2.3 + 0.5 = 2.8, int(2.8) = 2
+ 3
Just use print( int(total)) for interger
+ 2
Atul
There might be possibility of all test cases output is like
5.6
5.7
5.8
5.9
4.5
So if we use ceil or just add 0.5 and cast with int. In both cases output will be same.
+ 1
int(math.ceil(cost+(10*cost/100)))
+ 1
Lothar
I have solved in that way and passed all test cases.
+ 1
Atul
Well I don't know but I have passed all test cases 😀🤣
+ 1
Lothar
I think I also know whatever you want to say but fact is problem solved in that way. So I answered here. I will not give wrong solution.
0
I Am AJ ! now its passig 3 test cases and 2 test cases failed.And those two are hidden test cases
0
Use this line
0
I Am AJ ! I think so the difference in all cases are less than 0.5 . Correct me if I am incorrect
0
I Am AJ ! Yes because in all cases it will return int. So it's correct
0
Hey buddy, if you notice that game happens in (10/100)'s part of code where 0.1 will be multiplied by your cost then cost added and it will be total ....
Now total is in float value ...
And you need to convert it into int
Print(int(total))....
I hope it will help you and better your understanding to find an error by your self.
0
#i would rewrite your code and do it this way
x = int(input())
colours = 5.00*x
canvas_and_brushes = 40.00
tax = (colours + canvas_and_brushes)/10
total_cost = colours + canvas_and_brushes
print round(total_cost + tax)
#that should work, get back to me if im wrong