For this exercise, the always_false() function uses an and in the if statement to check the value of num. If the and is changed to an or, would the function become essentially always_true()?
Answer
NO, changing the and to an or does not convert the function from returning False always to returning True always. The condition where num is equal to 0 will return a value of False because the comparisons used are > and <. So, those tests will never evaluate to True for the case of num equals 0 and False or False will evaluate to False.
>>> def always_true(num):
return num and not not num or not num
>>> always_true(0)
True
>>> always_true(-1)
True
>>> always_true('')
True
>>> always_true([])
True
>>>
Been waiting for somebody to use ‘plus one’, and given this is a lesson where we can trust the inputs a perfectly logical solution.
Given that this much is now moot, let’s turn our attention to data type. We should be able to write a function that takes any type and returns a constant True, or a constant False, as the case may be.
According to the lesson, we will still need to perform an operation.