因为" round"将24 down 这样的数字舍入到二十,当我需要将答案舍入向上到30.请帮助我!我已经坚持了很久:(
答案 0 :(得分:0)
导入数学
def roundup(x):
#rounding method
return int(math.ceil(x / 10.0)) * 10
答案 1 :(得分:0)
此功能将正确向上和向下取整:
import math
def roundup(x, n=10):
res = math.ceil(x/n)*n
if (x%n < n/2)and (x%n>0):
res-=n
return res
num = [5,9,11,15]
r_num = [roundup(n) for n in num]
print(r_num)
# [10, 10, 10, 20]