Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

EricBerlin

  • 2 years ago

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?

  • This Question is Open
  1. FabienToune
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 4

    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): ")

  2. hook
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  3. hook
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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 ;)

  4. exchaoordo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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()

  5. frankdpnw
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks, I ws looking for the same thing and now I know how!

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

    Search OpenStudy
    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.