Problem with my code please help! (or a python glitch)

I am making a card game where the player is given three cards card1,card2 and card3, And I have the player choose what card to play - choice and a variable for when it is played - playedcard But no matter what card I say It to play, it always plays the last card.


But when I use elif it goes weird and chooses only the ones with if on them
(It wouldn’t let me put the other image in because I am new)
Is this some kind of glitch or a rookie mistake on my part?

Sorry Other screenshot was bad so I deleted it
here is the one with the weird stuff:

Please post text as text, rather than images of text.

But or doesn’t work like you think it does.

choice == "card 1" or "card1"

means:

  1. Compare choice to card one. If that’s True the whole thing is True.
  2. Otherwise, evaluate the string "card1" as a true/false value. Because it isn’t empty it evaluates to True.
  3. Therefore the whole thing is always True.

You probably mean

choice == "card 1" or choice == "card1"
1 Like

You have:

if input == "card 1" or "card1" or 1 or card1[0]:

That’s equivalent to:

if (input == "card 1") or "card1" or 1 or card1[0]:

input is the function you just used, and it’s not a string, so that equality test is false.

"card1" is a non-empty string, so that’s true.

The expression evaluates to true.

Also, 1 is an integer, but the result of the input function is a string, and a string is never equal to an integer.

2 Likes

oooh so because my 1 is an integer it takes it as true? Because of boolean?

Thanks for the answer! But why does me putting elif affect the output?