+ 5

# Code Coach : Paint problem

This is the code I have written ... 4/5 test cases passed ... Can you tell me What corrections should I make ? paint=int (input()) cost =40+(5*paint) tax=cost/10 total=cost+tax ans=round (total) print (ans)

10th Jan 2020, 7:37 AM
Sri Lakshmi + 5
I tried in python but i got small error Buy = int(input("")) def paint(n): color = n * 5 + 40 tax = color * 0.1 total = tax + color print (round(total)) n = Buy paint(n)
10th Jan 2020, 8:04 AM
Mohamed Sahal + 5
Use ceil function instead of round..
10th Jan 2020, 8:16 AM
Jayakrishna 🇮🇳
+ 3
Sri Lakshmi wel come..
10th Jan 2020, 11:31 AM
Jayakrishna 🇮🇳
+ 3
Michele I tried ...But for me, Test case 3 didn't pass with round function
10th Jan 2020, 1:42 PM
Sri Lakshmi + 3
Here is my attempt (it works): nb_paint = int(input()) print( round(( 40 + 5 * nb_paint ) * 1.1) )
10th Jan 2020, 6:11 PM
med gazzeh + 3
Michele round if not supplied by a second argument returns an int by default so I don't know if that changes anything.
10th Jan 2020, 6:13 PM
med gazzeh + 2
I solved this by using C++, here is my code #include <iostream> #include <cmath> using namespace std; int main() { float x, cost, colors; cin >> colors; //your code goes here x = 40.00 + (5.00*colors); cost = x + (x/10); cout <<(int) ceil(cost); return 0; }
10th Jan 2020, 8:03 AM
Mohamed Sahal + 2
Sri Lakshmi You are very welcome :D .Your code should work fine tho, there is something going around ,if I find anything I will let you know :)
10th Jan 2020, 6:43 PM
med gazzeh + 2
I solved it by java.. import java.util.Scanner; import java.lang.Math; public class Program { public static void main(String[] args) { int cc=5; int cb=40; double total; double result; Scanner sc = new Scanner(System.in); int nc = sc.nextInt(); if(nc>=0) { total=cc*nc + cb; result= total + Math.round(total/10); System.out.println(Math.round(result)); } } }
11th Jan 2020, 7:24 AM
Lukesh Singla + 2
Awad Alhaneen I can't understand what you are saying, but if you are looking for a solution to the paint cost problem here you go nb_paint = int(input()) print( round(( 40 + 5 * nb_paint ) * 1.1) ) If you don't understand it I will explain it: Input() is used to get an input from the user (and returns it in the form of a string) Int() function (not actually a function, it's a class, you will learn about classes later) that converts the parameter to an integer The print function prints things to the screen The round function rounds an the float/integer inside it to the nearest integer for exemple: round(5.5) #gives 6 round(5.4) #gives 5 round(5.0) # gives 5 round(5.9) #gives 6 If still can't understand the code you should probably redo the python lessons.
11th Jan 2020, 2:44 PM
med gazzeh + 2
x = int(input(“”)) def some(): cost = x * 5 + 40 tax = cost * 0.1 total = tax + cost print(round(total)) some()
11th Jan 2020, 3:04 PM
AlexRos + 2
anytime👍
11th Jan 2020, 3:34 PM
AlexRos + 2
Jayakrishna is right. I believe round approximates down for a value of x.5 to just x. Something about the assumptions it makes.
11th Jan 2020, 9:31 PM
Andrew Daab + 2
colors = int(input()) x = colors*5 + 40 withTax = round(x*1.1) print (withTax )
12th Jan 2020, 7:25 AM + 2
Andrew Daab I tried it gives round(x.y) gives x+1 if y>= 5 otherwise x But math.ceil always gives x+1 if y!=0 (as integer no need for int()).however ceil works here because the decimal part is always either 0 or 5 .so ceil is fine here but if the paints costed 4\$ for example ceil would give the wrong answer.
12th Jan 2020, 8:02 AM
med gazzeh + 2
med gazzeh Thank you for clarifying. That will be helpful in the future.
12th Jan 2020, 8:08 AM
Andrew Daab + 2
Andrew Daab Anytime :)
12th Jan 2020, 8:13 AM
med gazzeh + 2
Dinky try to post in your own separate thread.. You need to take total as float, and use ceil function to roundup result, then convert to int result.. Like these changes you need... float total=cost+tax; printf("%d",(int)ceil(total));
13th Apr 2020, 10:35 AM
Jayakrishna 🇮🇳
+ 1
Thanks for your effort & time Eng Xaliye I am trying but test case 3 alone is not passing...I am trying to figure out the reason...
10th Jan 2020, 8:30 AM
Sri Lakshmi + 1
Thanks Jayakrishna for ur time & effort .... Initially I used ceil without importing math module & hence I got error ...Now I used ceil function by importing math module & all test cases passed ...
10th Jan 2020, 10:49 AM
Sri Lakshmi 