Syntax error I can't figure out

Hello. I am learning PYthon, and have no idea why I am getting this error. Thanks in advance!

Cell In[2], line 3
text = text += random.choice(verb_choices)“”
^
SyntaxError: invalid syntax

""" Generate sentence type one """
def sentencetype1():
    rand = random.randint(1,2)
    if rand == 1:
        text = "I want to "
    if rand == 2:
        text = "I "
        verb_choices = random.sample(Verb, 12 + themevector1)
        text += random.choice(verb_choices)
        text += " the "
    if random.randint(1,2) == 1:
        adjective_choices = random.sample(Adjective, 12 + themevector1)
        text += random.choice(adjective_choices)
        noun_choices = random.sample(Noun, 12 + themevector1)
        text += random.choice(noun_choices)
    else:
        noun_choices = random.sample(Noun, 12 + themevector1)
        text += Noun[themevector1 + random.choice(12)]
    return text

The code you pasted on this site does not reflect what is in the error message.

In your original code, you wrote text = text += .... You need to either write text += ... or text = text + ...

1 Like

That’s what I have. It should work

Well, I ran the code you posted on my computer (first importing random) and it did not raise an exception.

I presume you can see why this is a syntax error. You can’t use += in an
expression, and the rest of the line after the leading text = is an
expression to evaluate and then put in text.

 Cell In[2], line 3
     text = text += random.choice(verb_choices)""
                 ^
 SyntaxError: invalid syntax

But I do not see the line above in the code you’ve quoted.