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

hoocke Group Title

Help please! I'm stuck with exercise 1.7 and how to decide what the user have written. What´s wrong? if (player1 != "Rock" or "Paper" or "Scissor"): print ("You can only write Rock, Paper or Scissor") inmatning()

  • one year ago
  • one year ago

  • This Question is Open
  1. andrew.m.higgs Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    How about using a while loop?

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

    How can that help me? I need to write a if-statement checking if the user is writing someting else than Rock, Paper or Scissor...

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

    andrew is correct in that you will need some kind of looping construct like a while loop to return and ask the user to try again to enter valid input. In the snippet you posted, as far as I know, you can't distribute the inequality test across the 'or's. Equality and inequality have higher precedence than the 'or' operation. Even if the language supports it, its easy to misinterpret. Its better to spell it out for anyone reading the code if (player1 != "Rock") and (player1 != "Paper") and (playe1 != "Scissor"): print ("You can only write Rock, Paper or Scissor") I threw in some clarifying parens and changed the conjunction to 'and' which I think is correct rather than 'or'. I have no idea what inmatning() is If there is any question about the syntax, you can always try a quick test in the Python interpreter

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

    @Screech, Are you sure the conjunction shouldn't be " or " ?....As in the player must input one "or" another of the 3 options.

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

    Yip. while player1 != "rock" or player1 != "scissors" or player1 != "paper": ask for user input You would need to use or because otherwise player1 would need to be all 3 values in order to exit the while loop.

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

    @hoocke Exercise 1.7 was just looking at ' if, elif,else' conditionals . So you ask for the input of player1 and player2. then, using if-elif compare them and give an appropriate print return. You can finish off with an else condition that tells the players 'This is not a valid object selection.' @andrew ...Phew, glad i got that right! I was worried i might have missed something! lol

    • one year ago
  7. andrew.m.higgs Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    My bad. Sorry. I should have checked the question again. :-)

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

    It's easy to forget what was covered when!... ;0)

    • one year ago
  9. yptrumpet Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    It looks like you guys have all the right elements for the logical evaluation, but in the wrong order. As it is, the while loop never terminates, even with the right player1 values. Should be one of the following, which are equivalent: while not(player1 == "rock" or player1 == "scissors" or player1 == "paper"): while (pOne != "rock" and pOne != "scissors" and pOne != "paper"): I don't know about you, but the confusion for me was that we usually write logical statements to see if input PASSES, but here we were checking for failure.

    • one year ago
  10. yptrumpet Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    (where pOne was my version of player1, my bad)

    • one year ago
  11. andrew.m.higgs Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    You are quite right. Trying to think to quickly. Shame on me....:-)

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

    Is this similar to what you have next =True while next == True: p1 = input("Player 1 please enter 'scissors', 'paper' or 'rock' ") p2 = input("Player 2 please enter 'scissors', 'paper' or 'rock' ") if (p1 != 'scissors' and p1 != 'paper' and p1 != 'rock') or (p2 != 'scissors' and p2 != 'paper' and p2 != 'rock'): print 'Both players must enter either scissors, paper or rock.' print continue else: if (p1 == 'scissors' and p2 == 'paper' or p1 == 'paper' and p2 == 'rock' or p1 == 'rock' and p2 == 'scissors'): print "Player 1 wins!" next = False elif(p2 == 'scissors' and p1 == 'paper' or p2 == 'paper' and p1 == 'rock' or p2 == 'rock' and p1 == 'scissors'): print "Player 2 wins!" next = False else: print "Players tie" print

    • one year ago
  13. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    if pl1=='rock' or pl1=='paper' or pl1=='scissors': do smthing else: ask user to try again. can this help?

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

    Thx all for the help!

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

    your welcome any time you have a problem email

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

    I just started sharing a DropBox folder with folks in my group. I am behind on programming exercises. Doing a lot of reading. I think I have all the programming for week 1 done. If you are interested in sharing my DropBox/PythonShare just email me at: richardgoodrich@gmail.com

    • 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.