-2

I'm trying to write a simple text-based game. Everything seems to be working. At the end, I want to add an option to play again. I put the whole thing in a loop and at the end, I added:

again = input('Would you like to play again? (Y/N) ')
if again == "Y" or "y":
    continue
else:
    break

Input seems to be storing the correct input but when compared to 'Y' or 'y' returns true no matter what the input is.

I confirmed that the input is correct. Edited the code to visualize it better.

again = input('Would you like to play again? (Y/N) ')
print(again)
if again == "Y" or "y":
    print("True")
else:
    print("False")

This was the output which didn't make sense to me.

Would you like to play again? (Y/N) n
n
True
Borisonekenobi
  • 469
  • 4
  • 15

2 Answers2

1

Try changing:

if again == "Y" or "y":

to:

if again == "Y" or again == "y":
Pragmatic_Lee
  • 473
  • 1
  • 4
  • 10
-2
if again == 'Y' or again == 'y':
Itération 122442
  • 2,644
  • 2
  • 27
  • 73