Getting invalid syntax on colon after my if statement


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<In what way does your code behave incorrectly? Include ALL error messages.>
on line 14 my if user_choice == computer_choice: I get a invalid syntax and the colon highlighted in red in python 3.6.5

<What do you expect to happen instead?>
to ask user for inout and after input was put in run the program to end

from random import randint
options = ["ROCK", "PAPER", "SCISSORS"]
message = {
   "tie": "Yawn it's a tie!",
   "won": "Yay you won!",
   "lost": "Aww you lost!" 
 }

def decide_winner(user_choice, computer_choice):
  print("You selected: {}".format(user_choice))
  print("Computer seleceted: {}".format(computer_choice)
  if user_choice == computer_choice:
    print(message["tie"])
  elif user_choice == options[0] and computer_choice == options[2]:
    print(message["won"])
  elif user_choice == options[1] and computer_choice == options[0]:
    print(message["won"])
  elif user_choice == options[2] and computer_choice == options[1]:
    print(message["won"])
  else:
    print(message["lost"])

def play_RPS():
  user_choice = input("Enter Rock, Paper, or Scissors: ")
  user_choice = user_choice.upper()
  computer_choice = options[randint(0, 2)]
  decide_winner(user_choice, computer_choice)
  
play_RPS()

#2

please look at the line of code above the error message:

print("Computer seleceted: {}".format(computer_choice)

notice anything odd?


#3

thanks I guess I got sloppy and didn’t even notice that I had two different named var and thats why I got the error code


#4

i was referring to the parentheses


#5

okay sorry but I am a noob and only have some idea about converting python 2 to python 3 i.e. (using. format instead of % or {} instead of %s for user input and input instead of user_input just to name a few but to the point i wanted to declare a str with the randint function that the computer selected to the user i.e. I select paper “you selected paper” then after the randint function runs for the computer it should say " Computer selected: {what ever randint was selected}" so is it the fact I didn’t put a space between {} and " or what I do apologize I did wind up re doing the exercise and got it to run but I still want to know what I messed up on so I can learn and identify my weaknesses or what is a common factor that I over look


#6
print("Computer seleceted: {}".format(computer_choice) // missing ) to close print

you just miss a ) which gives you the error.


#7

okay I see that now that you pointed it out thanks honestly that thing had stumped for hours and its funny to find out it was all because I didn’t make sure I had two ) instead of one thank you a lot for taking time to reply and explain my error to me.


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.