Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

EricBerlin Group Title

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?

  • one year ago
  • one year ago

  • This Question is Open
  1. FabienToune Group Title
    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): ")

    • one year ago
  2. hook Group Title
    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.

    • one year ago
  3. hook Group Title
    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 ;)

    • one year ago
  4. exchaoordo Group Title
    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()

    • one year ago
  5. frankdpnw Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • one year ago
    • Attachments:

See more questions >>>

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.