2

Because "round" will round a number such as 24 down to twenty, when I need the answer to be rounded up to 30. Please help me! I've been stuck on this for ages :(

Lord SammyBoi
  • 21
  • 1
  • 2

2 Answers2

0

Import math

def roundup(x):

#rounding method
return int(math.ceil(x / 10.0)) * 10
ljkj7
  • 1
0

This function will round both up and down, correctly:

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]

Yaakov Bressler
  • 9,056
  • 2
  • 45
  • 69