+ 1

What is the code to round up something

Hello. I'm wondering how do I round up something? My code a = int(input()) c = 40 p = 5 x = ((a * p + c)/10 + (a * p + c)) print(x)

13th Aug 2020, 9:47 PM
Codex
Codex - avatar
8 Antworten
+ 3
Another solution besides the math lib could look like this: a = int(input()) c = 40 p = 5 x =((a*p+c)/10+(a*p+c)) y = x - int(x) #y now contains everything after the floating point if y > 0: x -= y print(x) #with float point print(int(x)) #without float point
13th Aug 2020, 10:34 PM
Christian Hauck
Christian Hauck - avatar
+ 2
# use the math library, it makes it easy import math a = int(input()) c = 40 p = 5 x = ((a * p + c)/10 + (a * p + c)) print(math.ceil(x)) ''' https://realpython.com/JUMP_LINK__&&__python__&&__JUMP_LINK-rounding/ '''
13th Aug 2020, 9:52 PM
Steven M
Steven M - avatar
+ 2
Codex you should try using Google or any search engine of your choice maybe!
13th Aug 2020, 10:02 PM
Abhay
Abhay - avatar
+ 2
Christian Hauck Thanks man, but that doesn't seem to work I'm not quite sure why. I needed the code for the paint cost challenge and I tested yours and it can't pass the test.
13th Aug 2020, 11:01 PM
Codex
Codex - avatar
+ 2
Codex huh odd, i tried it once more and everything seems to be working as expected. https://code.sololearn.com/cLZo2T1UkbXc/?ref=app
13th Aug 2020, 11:16 PM
Christian Hauck
Christian Hauck - avatar
+ 2
Oooh i found my problem >~< Was roundig down and not up. Gotta add +1 to x after the if...
13th Aug 2020, 11:18 PM
Christian Hauck
Christian Hauck - avatar
+ 2
Oh yeah its working fine now thanks!
13th Aug 2020, 11:21 PM
Codex
Codex - avatar
+ 1
Thank you so much! your a life saver I've been stuck with this problem for hours
13th Aug 2020, 9:54 PM
Codex
Codex - avatar