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.