+ 2
Hii I'm trying to solve the paint costs challenge. Can someone pls tell me how to round to the nearest whole number?
colors=int(input()) total=40+colors*5 print(total+0.1*total)
7 Antworten
+ 3
You can round up a value by using ceil() function of math module.
ceil( total ) #import ceil()
You can round to some decimal places by round() function.
round(total)
round down to nearest integer by floor() function.
floor( total)
+ 2
Task
Given the total number of colors of paint that you need, calculate and output the total cost of your project rounded up to the nearest whole number.
Input Format
An integer that represents the number of colors that you want to purchase for your project.
Output Format
A number that represents the cost of your purchase rounded up to the nearest whole number.
Sample Input
10
Sample Output
99
+ 2
Jayakrishna 🇮🇳
I tried writing print(floor(total+0.1* total))
but it didn't work. What should I do?
+ 2
Floor() round down to nearest integer like 12.5 to 12, 23.8 to 23
To round up, you need 12.4 to 13, 12.8 to 13.0 so you need to apply ceil() function. Import math module before..
+ 2
You're welcome..
+ 1
Ok tysm!!
+ 1
Jayakrishna 🇮🇳 Okk thank you!