This code does not, for some reason work. It works with the 'and' command but I'm not completely sure how to use 'or'. My current code:
if (response1 not in symbols or letters):
print("You did something wrong")
This code does not, for some reason work. It works with the 'and' command but I'm not completely sure how to use 'or'. My current code:
if (response1 not in symbols or letters):
print("You did something wrong")
The or
in Python (and most programming languages for that matter) is not like the 'or' from spoken languages.
When you say
if (response1 not in symbols or letters)
Python actually interprets it as
if ((response1 not in symbols) or (letters))
which is not what you want. So what you should actually be doing is:
if ((response1 not in symbols) and (response1 not in letters))
or
is a logical operator. If the part before or
is true-ish, then that is returned, and if not, the second part is.
So here, either response1 not in symbols
is True and then that is returned, or otherwise letters
is returned. If there are things in letters
then it is true-ish itself, and the if
statement will consider it True.
You're looking for
if (response1 not in symbols) and (response1 not in letters):
print("You did something wrong")