Function to return the number of set bits in n
def set_bits ( n ) : NEW_LINE INDENT count = 0 NEW_LINE while ( n ) : NEW_LINE INDENT count += n % 2 NEW_LINE n //= 2 NEW_LINE DEDENT return count NEW_LINE DEDENT