11. The man behind the mask :( it still considers input as string :/


#1



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

11.the man behind the mask exercise in bit wise operations in python

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.


I expected it to work .. I First get input then transfer it to integer then to a binary number and compared it with & operator to the mask .. why did it still considering input as a string ?????


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


#2

Because bin returns a string -> https://docs.python.org/2/library/functions.html#bin

Binary number is just a number, take a look:

x = 0b1000
print x
=> 8

You don't have to modify input in any way.


#3

Aha :smiley: thanks a lot @factoradic


#4

You're very welcome! :slight_smile:


#5

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