+ 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)
8 odpowiedzi
+ 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
+ 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/
'''
+ 2
Codex you should try using Google or any search engine of your choice maybe!
+ 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.
+ 2
Codex huh odd, i tried it once more and everything seems to be working as expected.
https://code.sololearn.com/cLZo2T1UkbXc/?ref=app
+ 2
Oooh i found my problem >~<
Was roundig down and not up.
Gotta add +1 to x after the if...
+ 2
Oh yeah its working fine now thanks!
+ 1
Thank you so much! your a life saver I've been stuck with this problem for hours