0

What is different??

For the problem of paint cost in code coach i tried this 2 codes:- 1st n = int(input()) total = n*5 + 40 tax = total/10 print(int(round(tax+total,0))) 2nd n = int(input()) total = n*5 + 40 tax = round(total/10,0) print(int(tax+total)) If i use the 1st code the 3rd test case fails and if i use 2nd code 4th test case fails. Can some body help me understand what is wrong in both of these codes.

6th Jan 2020, 7:15 AM
Akash
Akash - avatar
3 ответов
+ 8
6th Jan 2020, 7:23 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 6
The Task description says that you should "round up" the result. In the code "round"() is used, but this is rounding to the next possible integer. This can be a rounding up, or a rounding down. So you have to use the "ceil()" function, which is always rounding up to the next integer. Therefore you have to import math like: from math import ceil then use ceil(...) instead of round()
6th Jan 2020, 7:59 AM
Lothar
Lothar - avatar
0
I solved the problem by the following method👇 n = int(input()) total = n*5 + 40 tax = total/10 tx =str(tax) if int(tx[-1])>=5: tax = int(tax)+1 else: tax = int(tax) print(tax+total)
6th Jan 2020, 11:41 AM
Akash
Akash - avatar