Monday 15 February 2010

python - How do i make use if? -


I am quite new to programming and I am working on rock, paper, scissor games. It does all the work except the previous part ( if part). X = ("rock") y = ("paper") z = ("scissor" print (x) print (y) print (z) choice = 1 (x, y, Z) Option 2 = (X, Y, Z) Import random printing ("player selected 1 ...") print (random.choice (Options1) print ("player 2 selected ...") print (random.choice ( Options2)) random.choice (options1) = rock and random.choice (options2) = scissors: print ("player 1 win")

whenever I try to execute the script I say, then it says:

  file "", line 14 if r Andom.choice (options1) = rock and random rice (option 2) = scissors: ^ syntax error: invalid syntax    

If you do not want to enter == not = :

  if random.choice (options1) == "rock" And random.choice (options2) == "Scissors": print ("Player 1 win")   

Second, as you rock and < No variables named code> scissors have been declared , so you should not have them cited around to make their wire Otherwise you NameError .

or variable x , z point to that string "rock" and "scissors":

  If random.choice (options1) == x and random.choice (options2) == z: print ("player 1 win")   

== similarity Is used for testing and for the = assignment.

  & gt; & Gt; & Gt; "Foo" == "bar" false & gt; & Gt; & Gt; "Foo" == "foo" true   

If the assignment is not permitted in Python's if statement, you receive SyntaxError Are there.

No comments:

Post a Comment