Use the Python round() function to round up to the nearest 10. You must divide the value by 10, round the result to zero precision, and multiply by 10 again.
Or you can pass a negative value for precision. The negative denotes that rounding happens to the left of the decimal point.
Python round up to nearest 10
A simple example code takes the number from the user, and round the value to its nearest 10 using the round() function.
number = int(input('Enter a number: ')) rounded = round(number/10)*10 print('Rounded Number :', rounded)
Using negative number as the second argument
rounded = round(number, -1)
You can use
math.ceil() to round up, and then multiply by 10
import math def roundup(x): return int(math.ceil(x / 10.0)) * 10 roundup(45)
Do comment if you have any doubts or suggestions on this Python round number topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.