This works but this doesnt?


#1



https://www.codecademy.com/courses/python-intermediate-en-KE1UJ/2/1?curriculum_id=4f89dab3d788890003000096#


Why does the first example work but the second does not? When I enter any bit other than 0b1000, I get an error message: "Your function fails on check_bit4(0b10). It returns "on" when it should return "off"."


Even if the bit was less than zero (per. function) it should return false. Im not sure where Im going wrong or right with this one.


# first example
def check_bit4(input):
    if input & 0b1000 > 0:
        return "on"
    else:
        return "off"
# second example
def check_bit4(input):
    if input & 0b101010 > 0:
        return "on"
    else:
        return "off"


#2

@ingame4th,
As part of the code testing
the code-checker sets up a function

    def answer(a):
        if a&b1000 > 0: 
           return "on"
        else: 
           return "off"

and then it tests a range of 0 to 10
comparing the outcome of your =code=
with the outcome of this answer() function....


#3

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