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 126 views
1 answer 112 views
1 answer 144 views
1 answer 95 views
1 answer 121 views
1 answer 123 views
1 answer 100 views
...