0
Why does the following not work? if letter == ('O' or 'Q'): statement
It only does the ststement if 'O' is true, not if 'Q' is true.
4 Réponses
+ 13
if letter=="O" or letter=="Q":
#......
+ 7
In this way you are trying to compare the letter variable already to the boolean result of the or statement. So you tell Python to check if letter == True, not if it is equal to any of those chars.
You should either decompose it like Valentin suggested or use the 'in' phrase:
if letter in ['Q', 'O']:
statement
It is more flexible because you can easily add consecutive letters only and not another 'or letter==' phrase.
+ 1
That worked, but i dont understand why the first only evaluates the first letter.
0
Thank you both! That makes sense!