Find the greater number closest to N having at most one non | Function to get closest greater number with at most non zero digit ; Stores the closest greater number with at most one non - zero digit ; Stores length of str ; Append 10 to the end of resultant String ; Append n - 1 times '0' to the end of resultant String ; Driver Code
def closestgtNum ( str ) : NEW_LINE INDENT res = " " ; NEW_LINE n = len ( str ) ; NEW_LINE if ( str [ 0 ] < '9' ) : NEW_LINE INDENT res += ( chr ) ( ord ( str [ 0 ] ) + 1 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT res += ( chr ) ( '1' ) ; NEW_LINE res += ( chr ) ( '0' ) ; NEW_LINE DEDENT for i in range ( n - 1 ) : NEW_LINE INDENT res += ( '0' ) ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str = "120" ; NEW_LINE print ( closestgtNum ( str ) ) ; NEW_LINE DEDENT