Invalid Syntax - RPS


Hello, I am new to programming and have been following the Codecademy python tutorials. I am used to working with jupyter notebooks so I tried copying my code onto there to run it and save the result.

I am creating a program that simulates a Rock-Paper-Scissors game. It worked fine in the Codecademy terminal, but it gives me an error when I try to run it in jupyter notebooks. I think it might be due to the fact that jupyter uses Python 3. Please help me to find my mistake.

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: %s’ % (user_choice))
print(‘The computer selected: %s’ % (computer_choice))
if user_choice == computer_choice:
elif user_choice == options[0] and computer_choice == options[2]:
elif user_choice == options[1] and computer_choice == options[0]:
elif user_choice == options[2] and computer_choice == options[1]:

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


It gives me the following error:
File “”, line 28
user_choice = user_choice.upper()
SyntaxError: invalid syntax

If I comment out that line, then it gives me an error on the next line. So there is some problem with the final block of code. Thanks for the help!!

PS. The indenting is correct, it just comes out weird when I copy the code onto here.


Hi @olgamatt,

Something is missing at the end of this line …

user_choice = int(input('Enter Rock, Paper, or Scissors: ')


hahaha ok that was very silly of me…but now when I run the code and enter a value of ‘rock’ for user choice it gives me this error:

ValueError Traceback (most recent call last)
in ()
30 decide_winner(user_choice, computer_choice)
—> 32 play_RPS()

in play_RPS()
26 def play_RPS():
—> 27 user_choice = int(input('Enter Rock, Paper, or Scissors: '))
28 user_choice = user_choice.upper()
29 computer_choice = options[randint(0,2)]

ValueError: invalid literal for int() with base 10: ‘rock’


Which version of Python are you using to execute the file? If it is version 2, use raw_input instead of input. If it is version 3, use input.

The current ValueError is raised by an attempt to convert 'rock' to an int. Remove the call to the int function in the statement that raised the ValueError, making sure to remove the left and right parentheses that correspond to that function call.


thank you - that worked!!