I just went through this example and wanted to shed some light on what you specifically got wrong
When you use bin(), you are creating a string with the integer's bit notation.
eg. bin(4) will generate "0b100"
when you are doing the & comparison, you need to be comparing two integers.
mask = 8
mask = 0b1000
These are both the exact same thing, where the 0b1000 is just another way of writing the number 8.
if 'bin(bin(input) & 0b1000):
in this section of the code, the "bin(input)" is turning the value of the "input" into a string of the bitwise value i.e. "0bx"
when you run the comparison of "bin(input) & 0b1000" you are now actually comparing a string with an integer.
Hope this clarifies the error.