+ 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)

11th Feb 2021, 10:26 AM
Guraja Teja Surya Lokesh Kumar
Guraja Teja Surya Lokesh Kumar - avatar
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))
11th Feb 2021, 10:51 AM
A͢J
A͢J - avatar
+ 7
Guraja Teja Surya Lokesh Kumar Do this print(int(total))
11th Feb 2021, 10:34 AM
A͢J
A͢J - avatar
+ 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
11th Feb 2021, 12:40 PM
Lothar
Lothar - avatar
+ 6
Guraja Teja Surya Lokesh Kumar It says to "round up", so use math.ceil(total) and don't forget to import math library.
11th Feb 2021, 10:42 AM
Abhay
Abhay - avatar
+ 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
11th Feb 2021, 11:44 AM
Lothar
Lothar - avatar
+ 3
Just use print( int(total)) for interger
11th Feb 2021, 1:49 PM
Angry Student(Docvad)
Angry Student(Docvad) - avatar
+ 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.
11th Feb 2021, 1:47 PM
A͢J
A͢J - avatar
+ 1
int(math.ceil(cost+(10*cost/100)))
11th Feb 2021, 10:50 AM
Atul [Inactive]
+ 1
Lothar I have solved in that way and passed all test cases.
11th Feb 2021, 11:48 AM
A͢J
A͢J - avatar
+ 1
Atul Well I don't know but I have passed all test cases 😀🤣
11th Feb 2021, 11:53 AM
A͢J
A͢J - avatar
+ 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.
11th Feb 2021, 1:25 PM
A͢J
A͢J - avatar
0
I Am AJ ! now its passig 3 test cases and 2 test cases failed.And those two are hidden test cases
11th Feb 2021, 10:40 AM
Guraja Teja Surya Lokesh Kumar
Guraja Teja Surya Lokesh Kumar - avatar
0
Use this line
11th Feb 2021, 10:51 AM
Atul [Inactive]
0
I Am AJ ! I think so the difference in all cases are less than 0.5 . Correct me if I am incorrect
11th Feb 2021, 11:52 AM
Atul [Inactive]
0
I Am AJ ! Yes because in all cases it will return int. So it's correct
11th Feb 2021, 2:32 PM
Atul [Inactive]
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.
12th Feb 2021, 8:07 PM
Nitesh Dwivedi
Nitesh Dwivedi - avatar
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
12th Feb 2021, 8:15 PM
Jack Jennings
Jack Jennings - avatar