anonymous
  • anonymous
Working on exercise 1.7 -- the Rock Paper Scissors game. My question: If the user types in something other than "rock," "paper, or "scissors," the program needs to loop back and ask for another input. Is there some way of using the IF command to do this? Is there some other command I am overlooking here?
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW)
chestercat
  • chestercat
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

anonymous
  • anonymous
What about this ? choices = ["rock", "paper", "scissors"] choice = raw_input("Your choice: ") while choice not in choices: choice = raw_input("Please enter a valid choice (rock, paper, scissors): ")
anonymous
  • anonymous
I just used the else statement for that, since if none of the valid combinations were present, someone didn’t write their right word. @FabienToune has written a version that asks for a correct choice already beforehand, which might be a better choice.
anonymous
  • anonymous
That being said, I balantly copied @FabienToune’s solution as well now and changed the `else` at the end as a warning if anything goes *really* wrong ;)

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
This is another example of the "not in list" syntax, which I like, but I don't think we got that in the instructions yet, so my insight was that it had to actually ask the same question twice. I used a while loop for this. It doesn't loop back so much as ask again: while again != ("n"): player1 = raw_input("Player 1?").lower() while (player1 != "rock" and player1 != "paper" and player1 != "scissors"): print "This is not a valid object selection" player1 = raw_input("Player 1?").lower()
anonymous
  • anonymous
Thanks, I ws looking for the same thing and now I know how!

Looking for something else?

Not the answer you are looking for? Search for more explanations.