I am trying to replace a string with the word [NOUN] on it. I'm clueless!
Here's my code below - which returns lots of errors - the variable story is a string and listOfNouns is a list - so I try and convert the string into a list by splitting it.:
def replacement(story, listOfNouns):
length = len(story1)
story1 = story.split()
for c in range(0,len(story1)):
if c in listOfNouns:
story1[c]= 'NOUN'
story = ''.join(story)
return story
Here's the error message that I get below when I call the above function with
replacement("Let's play marbles", ['marbles']):
Traceback (most recent call last):
File "<pyshell#189>", line 1, in <module>
replacement("Let's play marbels", ['marbels'])
File "C:/ProblemSet4/exam.py", line 3, in replacement
length = len(story1)
UnboundLocalError: local variable 'story1' referenced before assignment
How can I replace the new story1 list with another element from another list?
How do I modify the tuples and return the new string - which is supposed to say:
Let's play [NOUN]???
Can anyone please help out? I'm lost and i've been trying this for hours using all the knowledge I have in Python/Java to figure this crap out!