for two 's complement go from right  to left in ones complement and if  we get 1 make, we make them 0 and  keep going left when we get first  0, make that 1 and go out of loop
ones = list ( ones . strip ( " " ) ) NEW_LINE twos = list ( ones ) NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( ones [ i ] == '1' ) : NEW_LINE INDENT twos [ i ] = '0' NEW_LINE DEDENT else : NEW_LINE INDENT twos [ i ] = '1' NEW_LINE break NEW_LINE DEDENT DEDENT i -= 1 NEW_LINE