14. Slip and Slide


#1



I can't figure out what's wrong with this code. It gives me the error "Oops, try again. Your function fails on flip_bit('0b111', 2). It returns "None" when it should return "0b101"."


Using the little test code at the end that runs the function with the exact conditions that the error lists, I do get an output of 0b101. I'm not sure if the single quotes matter in this case and it's asking me to turn "number" from a string to a binary number or something, but I don't think that this is the case.


Replace this line with your code. 
def flip_bit(number, n):
    mask= 0b1<<(n-1)
    result=number^mask
    print bin(result)

flip_bit(0b111,2)


#2

You're printing result!

look at the error..

"Oops, try again. Your function fails on flip_bit('0b111', 2). It returns "None" when it should return "0b101"."

so you have to return result?

Note:
when we don't return anything function by default returns None.


#3

Oh ok. I knew I must have been making some kind of stupid mistake. Thank you so much!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.