Question: 
Write a python function to toggle only first and last bits of a given number.


Model's Code:
def toggle_F_and_L_bits(num):
    if num == 0:
        return 0
    # Get the first bit (highest order bit)
    first_bit = num & (1 << (num.bit_length() - 1))
    # Get the last bit (least significant bit)
    last_bit = num & 1
    # Toggle first bit if it is set
    if first_bit:
        num ^= (1 << (num.bit_length() - 1))
    # Toggle last bit if it is set
    if last_bit:
        num ^= 1
    return num



Sample Correct Code:
def take_L_and_F_set_bits(n) : 
    n = n | n >> 1
    n = n | n >> 2
    n = n | n >> 4
    n = n | n >> 8
    n = n | n >> 16 
    return ((n + 1) >> 1) + 1      
def toggle_F_and_L_bits(n) :  
    if (n == 1) : 
        return 0 
    return n ^ take_L_and_F_set_bits(n) 


Asserts:
assert toggle_F_and_L_bits(10) == 3
assert toggle_F_and_L_bits(15) == 6
assert toggle_F_and_L_bits(20) == 5


Tests:
Test 1 of 3: FAIL: AssertionError()

Test 545 of 974: 402/545 (73.76146788990826%): failed