-6

I am making a Rock, Paper, Scissors game for my school project and it was finished but it suddenly stopped working. I think it is a problem in the while loop.

while UserHand or UserHand_Retry != "Rock" and UserHand or UserHand_Retry != "Paper" and UserHand or UserHand_Retry != "Scissors":
    tkMessageBox.showerror("ERROR!","You did not choose a valid object, please try again.")
    UserHand_Retry = raw_input("What do you want to choose? (Rock/Paper/Scissors):")
  • 3
    *"it suddenly stopped working"* is not helpful. What is not working? Is it throwing an error message? Is it producing incorrect results? – Cory Kramer Jan 07 '15 at 20:00
  • define "it suddenly stopped working". Is it throwing an error or what? – user2097159 Jan 07 '15 at 20:00
  • 1
    A program like this doesn't just randomly stop working - more likely, *you changed something that broke it*. Change it back! – jonrsharpe Jan 07 '15 at 20:01
  • 1
    `UserHand or UserHand_Retry == "Rock"` does not do what you think it does. See http://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-multiple-values – Kevin Jan 07 '15 at 20:03
  • Also consider taking this over to code review once it is working. There's a lot of clutter that could be cleaned up. – user2097159 Jan 07 '15 at 20:04
  • Sorry if I was not clear enough, but no matter what I do, if I use Rock, Paper or Scissors it gives the error message again and again. – Jeroen van der Wal Jan 07 '15 at 21:37

1 Answers1

1

Your while condition will be True if UserHand is any non-empty value, like 'a', or '3333', because of

UserHand or UserHand_Retry....

since or needs only one of these to be True and UserHand will be evaluated as True if it's a non-empty string.

while UserHand not in ["Rock", "Paper", "Scissors"]:

Also, be careful with multiple or and and in your condition; that might work differently than you expected. Use ( and ) if you're unsure.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Andrew_Lvov
  • 4,621
  • 2
  • 25
  • 31
  • It would be helpful to add *at the very least* where this line should go, and much better if you explained why it's better than what it's replacing. – jonrsharpe Jan 07 '15 at 20:19
  • @jonrsharpe, The code is self explanatory for any programmer with even a smidgen of common sense. ++. In fact, most answers require no explanation. – 7stud Jan 07 '15 at 20:21
  • 3
    While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – msrd0 Jan 07 '15 at 20:21
  • There is only one place with while. You're right about explanation, I guess – Andrew_Lvov Jan 07 '15 at 20:21
  • Added explanation, thank you for comments – Andrew_Lvov Jan 07 '15 at 20:24
  • @jonrsharpe, thank your for style fixes, didn't know I can do that inline – Andrew_Lvov Jan 07 '15 at 20:42
  • I will try to use this list tomorrow and thanks everyone for helping me, starting on this website! – Jeroen van der Wal Jan 07 '15 at 21:52