ââ" 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
Can you please format your code by surrounding it with triple backticks (```)? We canât tell what itâs supposed to be without proper indentation.
What I think @MRAB was asking is what you expect a statement of the form a = a += b to do. Thatâs what it looks you you wrote in the original exception message (though itâs hard to be sure without proper formatting). Curiously there doesnât seem to be a line matching that in the second code snippet you posted, so Iâd recommend double checking that you properly saved the file / re-ran any previous cells after editing.
""" 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
It doesnât look like that code will produce the exception you got.
Do you get the same error if you re-run the cell? Be sure to re-run any cells that define functions youâve edited. If the error persists, can you post the full exception trace back as formatted text?