A community for students.
Here's the question you clicked on:
 0 viewing
hoocke
 4 years ago
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()
hoocke
 4 years ago
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()

This Question is Open

andrew.m.higgs
 4 years ago
Best ResponseYou've already chosen the best response.0How about using a while loop?

hoocke
 4 years ago
Best ResponseYou've already chosen the best response.0How can that help me? I need to write a ifstatement checking if the user is writing someting else than Rock, Paper or Scissor...

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0andrew 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

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0@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
 4 years ago
Best ResponseYou've already chosen the best response.0Yip. 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
 4 years ago
Best ResponseYou've already chosen the best response.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 ifelif 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
 4 years ago
Best ResponseYou've already chosen the best response.0My bad. Sorry. I should have checked the question again. :)

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0It's easy to forget what was covered when!... ;0)

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0It 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
 4 years ago
Best ResponseYou've already chosen the best response.0(where pOne was my version of player1, my bad)

andrew.m.higgs
 4 years ago
Best ResponseYou've already chosen the best response.0You are quite right. Trying to think to quickly. Shame on me....:)

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0Is 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
 4 years ago
Best ResponseYou've already chosen the best response.1if pl1=='rock' or pl1=='paper' or pl1=='scissors': do smthing else: ask user to try again. can this help?

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0your welcome any time you have a problem email

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0I 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
Ask your own question
Sign UpFind 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
 Engagement 19 Mad Hatter
 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.