The man behind the mask


The result of this program is correct, that codecademy said. But why there is no message of result in output.

def check_bit4(input):
checkBit = 0b1000
checker = checkBit & input
if checker > 0:
return 'on’
return 'off’
number = 0b1101
print check_bit4(number)


I have just understand. The problem was in indentation


Extra study

Python has some beautiful syntax (ternary) for this type of problem:

>>> def check_bit4(number):
	return 'on' if number & 0b1000 else 'off'

>>> check_bit4(8)
>>> check_bit4(10)
>>> check_bit4(24)
>>> check_bit4(33)

Also, we should not make a practice of using reserved words as variables. Use in a parameter does not cause any problems (because of local scope) fortunately, but it is still not a good practice.


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