Nearest multiple of 10 Python

PROGRAM TO ROUND THE GIVEN NUMBER TO NEAREST MULTIPLE OF 10



# function to round the number
def round( n ):
 
    # Smaller multiple
    a = (n // 10) * 10
     
    # Larger multiple
    b = a + 10
     
    # Return of closest of two
    return (b if n - a > b - n else a)
 
# driver code
n = 4722
print(round(n))

OUTPUT
4720

Comments

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java