Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 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()
 2 years ago
 2 years ago
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()
 2 years ago
 2 years ago

This Question is Open

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

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

Screech Group TitleBest ResponseYou've already chosen the best response.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
 2 years ago

petew71 Group TitleBest 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.
 2 years ago

andrew.m.higgs Group TitleBest ResponseYou've already chosen the best response.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.
 2 years ago

petew71 Group TitleBest 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
 2 years ago

andrew.m.higgs Group TitleBest ResponseYou've already chosen the best response.0
My bad. Sorry. I should have checked the question again. :)
 2 years ago

petew71 Group TitleBest ResponseYou've already chosen the best response.0
It's easy to forget what was covered when!... ;0)
 2 years ago

yptrumpet Group TitleBest ResponseYou've already chosen the best response.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.
 2 years ago

yptrumpet Group TitleBest ResponseYou've already chosen the best response.1
(where pOne was my version of player1, my bad)
 2 years ago

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

lh4219 Group TitleBest ResponseYou've already chosen the best response.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
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
if pl1=='rock' or pl1=='paper' or pl1=='scissors': do smthing else: ask user to try again. can this help?
 2 years ago

hoocke Group TitleBest ResponseYou've already chosen the best response.0
Thx all for the help!
 one year ago

lh4219 Group TitleBest ResponseYou've already chosen the best response.0
your welcome any time you have a problem email
 one year ago

RichardGoodrich Group TitleBest ResponseYou've already chosen the best response.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
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
 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.