I want to list several vairables in a function so they will all be detected:
if how != 'no'or'yes':
print"That is not a valid answer"
so i want the if how != to read no and yes but when i run only no is detected
I want to list several vairables in a function so they will all be detected:
if how != 'no'or'yes':
print"That is not a valid answer"
so i want the if how != to read no and yes but when i run only no is detected
in your if condition:
if how != 'no' or 'yes':
you're making a wrong assessment, it's that python will understand that the value of how
is either no
or yes
, like you would do in a natural language.
But what you're actually testing is whether how
is different from no
and whether yes
is different from None
:
if how != 'no' or 'yes' != None:
and the latter will always valuate to true.
The correct way to express your logic would be:
if how != 'no' or how != 'yes'
to be a bit more pythonic:
if not how == 'no' or not how == 'yes'
and the totally pythonic solution:
if how not in ('yes', 'no')