11. The man behind the mask: Right output but programm says my code is wrong


def check_bit4(input):
newIn = input >> 3
if newIn == 1:
print "on"
print "off"


The console returns "off" and the environment throws the error:

Oops, try again.
Your function fails on check_bit4(0b0). It returns "None" when it should return "off".

What did I do wrong, how to get the program to "see" that my code is right?


replace the print statements with return


thank you, that was the problem


Ha! That's quite a funny way of tackling the question! Kudos for thinking outside the box :smile: You're not masking here though, so the solution won't work if you're asked to check more than one bit. In that case you'd be back to masking:

def check_bits4_2(input):
    if ((input & 0b1010) > 0):
        return "on"
        return "off"


def check_bit4(inout):
if inout >>3 >0:
return "on"

    return "off"

print check_bit4(0b01000)


Here is the code I used that works

def check_bit4(input):
mask = 0b1000
test = input & mask
if test > 0:
return "on"
return "off"
print check_bit4