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

42 Answers

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

+ 5

Use ceil function instead of round..

+ 3

Sri Lakshmi wel come..

+ 3

Michele I tried ...But for me, Test case 3 didn't pass with round function

+ 3

Here is my attempt (it works):
nb_paint = int(input())
print( round(( 40 + 5 * nb_paint ) * 1.1) )

+ 3

Michele round if not supplied by a second argument returns an int by default so I don't know if that changes anything.

+ 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;
}

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

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

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

+ 2

x = int(input(“”))
def some():
cost = x * 5 + 40
tax = cost * 0.1
total = tax + cost
print(round(total))
some()

+ 2

anytime👍

+ 2

Jayakrishna is right. I believe round approximates down for a value of x.5 to just x. Something about the assumptions it makes.

+ 2

colors = int(input())
x = colors*5 + 40
withTax = round(x*1.1)
print (withTax )

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

+ 2

med gazzeh
Thank you for clarifying. That will be helpful in the future.

+ 2

Andrew Daab
Anytime :)

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

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

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