Whenever I try to run this I get the following message: "Your function fails on flip_bit('0b111', 2). It returns "None" when it should return "0b101"."
However, when I call "flip_bit('0b111', 2)" I get this message:
Traceback (most recent call last):
File "python", line 6, in
File "python", line 3, in flip_bit
TypeError: unsupported operand type(s) for ^: 'str' and 'int'
When I run "flip_bit(0b11111,2)" , it works fine and outputs "0b11101".
It seems like the problem is that it's trying to input a string when it needs to be a binary number. Is this the case, or am I doing something wrong?
def flip_bit(number,n): mask = 0b1 << n - 1 result = number ^ mask print bin(result) flip_bit(0b11111,2) flip_bit('0b111', 2)