Yes or No output Python
python, variables
Solution
if Join == 'yes' or 'Yes':
This is always true. Python reads it as:
if (Join == 'yes') or 'Yes':
The second half of the `or`, being a non-empty string, is always true, so the whole expression is always true because anything `or` true is true.
You can fix this by explicitly comparing `Join` to both values:
if Join == 'yes' or Join == 'Yes':
But in this particular case I would suggest the best way to write it is this:
if Join.lower() == 'yes':
This way the case of what the user enters does not matter, it is converted to lowercase and tested against a lowercase value. If you intend to use the variable `Join` elsewhere it may be convenient to lowercase it when it is input instead:
Join = input('Would you like to join me?').lower()
if Join == 'yes': # etc.
You could also write it so that the user can enter anything that begins with `y` or indeed, just `y`:
Join = input('Would you like to join me?').lower()
if Join.startswith('y'): # etc.
Problem
``` Join = input('Would you like to join me?') if Join == 'yes' or 'Yes': print("Great," + myName + '!') else: print ("Sorry for asking...") ``` So this is my code. It's longer; just including the problem. I'm asking a yes or no question and when in the console it runs smoothly until you get to it. Whatever you type you get the 'yes' output. Could someone please help? I've used elif statements as well but no luck.