Round the given number to nearest multiple of 10 | Function to round the number to the nearest number having one 's digit 0 ; Last character is 0 then return the original string ; If last character is 1 or 2 or 3 or 4 or 5 make it 0 ; Process carry ; Return final string ; Driver code ; Function call
def Round ( s , n ) : NEW_LINE INDENT s = list ( s ) NEW_LINE c = s . copy ( ) NEW_LINE if ( c [ n - 1 ] == '0' ) : NEW_LINE INDENT return ( " " . join ( s ) ) NEW_LINE DEDENT elif ( c [ n - 1 ] == '1' or c [ n - 1 ] == '2' or c [ n - 1 ] == '3' or c [ n - 1 ] == '4' or c [ n - 1 ] == '5' ) : NEW_LINE INDENT c [ n - 1 ] = '0' NEW_LINE return ( " " . join ( c ) ) NEW_LINE DEDENT else : NEW_LINE INDENT c [ n - 1 ] = '0' NEW_LINE for i in range ( n - 2 , - 1 , - 1 ) : NEW_LINE INDENT if ( c [ i ] == '9' ) : NEW_LINE INDENT c [ i ] = '0' NEW_LINE DEDENT else : NEW_LINE INDENT t = ord ( c [ i ] ) - ord ( '0' ) + 1 NEW_LINE c [ i ] = chr ( 48 + t ) NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT s1 = " " . join ( c ) NEW_LINE if ( s1 [ 0 ] == '0' ) : NEW_LINE INDENT s1 = "1" + s1 NEW_LINE DEDENT return s1 NEW_LINE DEDENT s = "5748965412485599999874589965999" NEW_LINE n = len ( s ) NEW_LINE print ( Round ( s , n ) ) NEW_LINE