I could use some guidance as I'm new to python and trying to figure out if we can use integer values of 0 and 1 in order to return our own customized message within the same function where I'm trying to reverse the Boolean values.
def reverse_bool_value(value):
if value == True:
return not value
elif value == False:
return not value
elif type(value) == int:
return "Not Boolean Value"
else:
return "Boolean Expected"
>>>reverse_bool_value(12)
'Not Boolean Value'
>>>reverse_bool_value(1)
False
>>> reverse_bool_value(0)
True
The function works fine if I enter in any integers (except 0 and 1), float, complex, string values and Boolean conditions of True and False, it returns me the expected outcome.
Accept when I use 0 or 1...it does not return me the customized message given "Not Boolean Value", rather it returns True for 0 (as the condition is reversed) and False for 1. I appreciate that using both inside the same condition of validating between integer and bool does not work, as quite evident. But I would really appreciate some help, as to how should I go around it in order for this to work. Is there a way?? Thank you.