input: Write a Python function that inverts the bits of a number, leaving the first and last bits unchanged.  
  assert toggle_middle_bits(9) == 15  
  assert toggle_middle_bits(10) == 12  
  assert toggle_middle_bits(11) == 13
output: def toggle_middle_bits(n):
      if n == 0:
          return 0
      bin_str = bin(n)[2:]
      if len(bin_str) <= 2:
          return n
      middle_bits_inverted = ''.join('1' if b == '0' else '0' for b in bin_str[1:-1])
      inverted_str = bin_str[0] + middle_bits_inverted + bin_str[-1]
      return int(inverted_str, 2)