Python3 program to convert positive decimals into balanced ternary system
def balancedTernary ( n ) : NEW_LINE INDENT output = " " NEW_LINE while ( n > 0 ) : NEW_LINE INDENT rem = n % 3 NEW_LINE n = n // 3 NEW_LINE if ( rem == 2 ) : NEW_LINE INDENT rem = - 1 NEW_LINE n += 1 NEW_LINE DEDENT if ( rem == 0 ) : NEW_LINE INDENT output = '0' + output NEW_LINE DEDENT else : NEW_LINE INDENT if ( rem == 1 ) : NEW_LINE INDENT output = '1' + output NEW_LINE DEDENT else : NEW_LINE INDENT output = ' Z ' + output NEW_LINE DEDENT DEDENT DEDENT return output NEW_LINE DEDENT