Hello. I am getting this error. Massive thanks in advance for helping me with this!!
“”" Generate story “”"
paracount = 1
while paracount < numberparas:
paragraphbuilder()
paragraph = paragraphbuilder()
print(paragraph)
story = story + paragraph
paracount += 1
UnboundLocalError Traceback (most recent call last)
Cell In[129], line 5
3 while paracount < numberparas:
4 paragraphbuilder()
----> 5 paragraph = paragraphbuilder()
6 print(paragraph)
7 story = story + paragraph
Cell In[128], line 16, in paragraphbuilder()
14 sentences.append(settingsentence1())
15 if y in range(19, 20):
—> 16 narrative = narrative + 1
17 if narrative == 1:
18 sentences.append(plotsentence1())
UnboundLocalError: cannot access local variable ‘narrative’ where it is not associated with a value
narrative = 0
def paragraphbuilder():
sentences = []
if paracount > 1:
sentences.append(" ")
for _ in range(random.randint(1,50)):
y = random.randint(1,20)
if y in range(1, 4):
sentences.append(sentencetype1())
if y in range(5):
sentences.append(weathersentence1())
if y in range(6, 10):
sentences.append(subjectsentence1())
if y in range(11, 18):
sentences.append(settingsentence1())
if y in range(19, 20):
narrative = narrative + 1
if narrative == 1:
sentences.append(plotsentence1())
if narrative == 2:
sentences.append(plotsentence2())
sentences.append("\n")
return " ".join(sentences)