The Man Behind The Mask


I keep getting the message:
"Oops, try again. Does your check_bit4 function take exactly one argument (an integer)? Your code threw a "unsupported operand type(s) for &: 'str' and 'int'" error. "

It should check to see if the fourth bit from the right of the input variable is on then return on if it is, or off if it is not.
How do I get rid of the error message and pass the test?

This is what I coded...

def check_bit4(input):
    input = int(input)
    input = bin(input)
    mask = 0b1000
    desired = input & mask
    if desired > 0:
        return "on"
        return "off"

What am I doing wrong?


bin() returns string (string of 1's and 0's) and not a binary number actually. also input is already an int so casting using int() constructor seems useless.

You can delete that line of code?


Thanks for explaining lines I can remove.
Any advice on lines I can add?


Is code working or It has still having the bug ?


Thought there was something I hadnt coded into the algorithm.
Thanks. But if I may ask what exactly does the input keyword do?


input is not a keyword in python but built-in function (precisely it's input() ) so we are able to create variable name(identifier) using that.
here it's a variable name, that is of integer type.
keywords in python can't used as identifier(object names).


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