How to round a number up to the nearest 5 in Python

1 Answer

0 votes
import math 
 
def roundUpToNearest5(num):
    return math.ceil(num / 5) * 5
     
print(roundUpToNearest5(13))
print(roundUpToNearest5(14))
print(roundUpToNearest5(16))

print(roundUpToNearest5(7))
print(roundUpToNearest5(3))
print(roundUpToNearest5(4))
print(roundUpToNearest5(5))
 
print(roundUpToNearest5(-1))
print(roundUpToNearest5(-9))
 
 
 
 
 
'''
run:
 
15
15
20
10
5
5
5
0
-5

'''

 



answered Jul 17, 2022 by avibootz

Related questions

1 answer 136 views
1 answer 121 views
1 answer 156 views
1 answer 103 views
1 answer 133 views
1 answer 130 views
1 answer 110 views
...