Program to insert dashes between two adjacent odd digits in given Number | Function to check if char ch is odd or not ; Function to insert dash - between any 2 consecutive digit in string str ; Traverse the string character by character ; Compare every consecutive character with the odd value ; Print the resultant string ; Given number in form of string ; Function call
def checkOdd ( ch ) : NEW_LINE INDENT return ( ( ord ( ch ) - 48 ) & 1 ) NEW_LINE DEDENT def Insert_dash ( num_str ) : NEW_LINE INDENT result_str = num_str NEW_LINE x = 0 NEW_LINE while ( x < len ( num_str ) - 1 ) : NEW_LINE INDENT if ( checkOdd ( num_str [ x ] ) and checkOdd ( num_str [ x + 1 ] ) ) : NEW_LINE INDENT result_str = ( result_str [ : x + 1 ] + ' - ' + result_str [ x + 1 : ] ) NEW_LINE num_str = result_str NEW_LINE x += 1 NEW_LINE DEDENT x += 1 NEW_LINE DEDENT return result_str NEW_LINE DEDENT str = "1745389" NEW_LINE print ( Insert_dash ( str ) ) NEW_LINE