hoocke
  • hoocke
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()
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
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.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
andrew.m.higgs
  • andrew.m.higgs
How about using a while loop?
hoocke
  • hoocke
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...
anonymous
  • anonymous
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

Looking for something else?

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

More answers

anonymous
  • anonymous
@Screech, Are you sure the conjunction shouldn't be " or " ?....As in the player must input one "or" another of the 3 options.
andrew.m.higgs
  • andrew.m.higgs
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.
anonymous
  • anonymous
@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
andrew.m.higgs
  • andrew.m.higgs
My bad. Sorry. I should have checked the question again. :-)
anonymous
  • anonymous
It's easy to forget what was covered when!... ;0)
anonymous
  • anonymous
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.
anonymous
  • anonymous
(where pOne was my version of player1, my bad)
andrew.m.higgs
  • andrew.m.higgs
You are quite right. Trying to think to quickly. Shame on me....:-)
anonymous
  • anonymous
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
MicroBot
  • MicroBot
if pl1=='rock' or pl1=='paper' or pl1=='scissors': do smthing else: ask user to try again. can this help?
hoocke
  • hoocke
Thx all for the help!
anonymous
  • anonymous
your welcome any time you have a problem email
anonymous
  • anonymous
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

Looking for something else?

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