Syntax Error question

Just learning how to code with pycharm. I was trying to make a rock paper scissors game, and kept getting random syntax errors usually relating to quotes. I ended up copying the entire script from the website I was using into pycharm (only like 15 lines), and kept getting the same syntax errors. The site had several reviews at the bottom saying the code was chill and worked for them so I trust (i think) the code. Reinstalled pycharm and python and was still getting the same errors. Any ideas? heres the code:

import random

user_action = input(“Enter a choice (rock, paper, scissors): “)
possible_actions = [“rock”, “paper”, “scissors”]
computer_action = random.choice(possible_actions)
print(f”\nYou chose {user_action}, computer chose {computer_action}.\n”)

if user_action == computer_action:
print(f’Both players selected {user_action}. It’s a tie!’)
elif user_action == “rock”:
if computer_action == “scissors”:
print(“Rock smashes scissors! You win!”)
else:
print(“Paper covers rock! You lose.”)
elif user_action == “paper”:
if computer_action == “rock”:
print(“Paper covers rock! You win!”)
else:
print(“Scissors cuts paper! You lose.”)
elif user_action == “scissors”:
if computer_action == “paper”:
print(“Scissors cuts paper! You win!”)
else:
print(“Rock smashes scissors! You lose.”)

You need to copy the entire error message if you want us to be able to help you. Failing that, here are a few pointers.

Firstly, indentation is essential in Python. Here is what I’m guessing your code should look like.

import random

user_action = input(“Enter a choice (rock, paper, scissors): “)
possible_actions = [“rock”, “paper”, “scissors”]
computer_action = random.choice(possible_actions)
print(f”\nYou chose {user_action}, computer chose {computer_action}.\n”)

if user_action == computer_action:
    print(f’Both players selected {user_action}. It’s a tie!’)
elif user_action == “rock”:
    if computer_action == “scissors”:
        print(“Rock smashes scissors! You win!”)
    else:
        print(“Paper covers rock! You lose.”)
elif user_action == “paper”:
    if computer_action == “rock”:
        print(“Paper covers rock! You win!”)
    else:
        print(“Scissors cuts paper! You lose.”)
elif user_action == “scissors”:
    if computer_action == “paper”:
        print(“Scissors cuts paper! You win!”)
    else:
        print(“Rock smashes scissors! You lose.”)

Secondly, you need to make sure that the quotation marks you use are regular quotation marks, " and ', and not fancy ones like you see reproduced in the code above.
Thirdly, on the second print statement, you need to enclose the f-strings with double quotes since there is a single quote in the sentence It's a tie.

Hi Maxwell,

If you are getting syntax errors, that means there is a problem with the
code that needs to be fixed. It is never a problem with Python or
PyCharm that can be fixed by reinstalling.

At worst, it might be that you need a newer version of Python, but
reinstalling the same old version will not help.

Start by looking at the syntax error. It will tell you what is wrong, or
at least give you a hint by pointing to where the Python interpreter
first spotted the problem.

Unfortunately, syntax errors can sometimes be hard for the interpreter
to explain precisely what is wrong. Sometimes the real error might
even be a line or two before where the syntax error points. But even in
the worst case, the syntax error will help narrow down where and what
the problem is.

Looking at the code you give, there doesn’t seem to be any obvious
problem. All the quotes seem to be okay. It might be that if you are
using an old version of Python that doesn’t understand f-strings:

f'Both players selected ...'

If that is the case, you will need to install a newer version of
Python, not the same old version.

To diagnose the error, please show us the full error message, starting
from the beginning. It will look something like:

File "filename.py", line 1234
    x = 2 4
        ^^^
SyntaxError: ...

except of course the line of code will be different. Copy and paste the
error message, don’t use a screen shot or photo.

It will also help if you tell us what version of Python you are using.
If you are unsure, run this:

import sys
print(sys.version)

and copy and paste the output.

Hi Maxwell,
I think the quotes are wrong. Python uses " (34) and ’ (39), but you are using “ (8220) and ” (8221).
You can check this by using ord(’”’).

Earlier I suggested the Maxwell’s code looked fine to me. I was wrong.

In the email that Discuss sends out, Maxwell’s code uses regular ASCII
double and single quotes " and ’ but in the text on the Discuss website,
the quotes are actually curly quotation marks, e.g.:

possible_actions = [“rock”, “paper”, “scissors”]

Those are curly quotes, chr(8220) and chr(8221), not regular ASCII
quotes " chr(34).

Thank you to Nacho xxl for alerting me to that possibility.

So here is a lesson for me: apparently Discuss changes the text of
people’s posts when it sends them out as emails. I cannot trust the
Discuss emails to be accurate copies of what people have typed.

Maxwell: you cannot use curly quotes, or so-called “smart quotes”, when
programming in Python. You must use plain old type-writer ASCII quotes.

By the way, in the most recent version of Python, the interpreter says:

>>> “abc”
  File "<stdin>", line 1
    “abc”
    ^
SyntaxError: invalid character '“' (U+201C)

so it tells you exactly what is wrong.

Older versions of Python may not be quite so smart.