0

I am trying to restart my program in python, but, for some reason, the code is getting caught up in the while playagain loop. It says "That was not a valid answer. Please enter 'yes' or 'no'." when I enter yes, no, or any of the other inputs that are acceptable. Why won't this work?

while True:
    playagain = input("Would you like to play again?")
    while playagain != "y" or playagain != "Y" or playagain != "Yes" or playagain != "yes" or playagain != "YES" or playagain != "n" or playagain != "N" or playagain != "No" or playagain != "no" or playagain != "NO":
         print("That was not a valid answer. Please enter 'yes' or 'no'.")
         playagain = input("Would you like to play again?")
    if playagain == "y" or playagain == "Y" or playagain == "Yes" or playagain == "yes" or playagain == "YES":
         break
    else:
         print("Thank you for playing MadLibs!")
Chris Martin
  • 29,484
  • 8
  • 71
  • 131
  • I've closed this as a duplicate of a question which explains how `or` behaves, and why `x != "y" or "Y" etc` doesn't work the way you think it does. – DSM Oct 06 '14 at 02:57
  • oh, ok. could you please link where this is explained? – xnathanmeyerx Oct 06 '14 at 03:03
  • If you click on the link after "This question already has an answer here" at the top of your question, you'll be taken to a question which has a good answer explaining how it works. – DSM Oct 06 '14 at 03:04
  • ok, I went to the article and put while x != "y" or x != "Y" or x != "yes" etc. but the error that I explained above is still occurring. Why is it still happening? – xnathanmeyerx Oct 06 '14 at 03:18

0 Answers0