Try y == 'n' or y =='no'
instead of y == 'n' or 'no'
>>> y = 'anything'
>>>
>>> bool(y == 'n' or 'no')
True
your statement always returns True
. Instead of checking y == 'no'
it just checks 'no'
, anything converted to bool in python is True
if its not None
, False
, or 0
.
In case of strings and other iterables it returns True if its not empty, e.g. ''
, []
, {}
, ()
will always return False
.
Or as Foo Bar User says, if y.lower() in ('n', 'no')
will also do. lower()
will make sure that the matching is case insensitive.