Pls help def generateForm(story, listOfAdjs, listOfNouns, listOfVerbs): """ story: a string containing sentences listOfAdjs: a list of valid adjectives listOfNouns: a list of valid nouns listOfVerbs: a list of valid verbs For each word in story that is in one of the lists, * replace it with the string '[ADJ]' if the word is in listOfAdjs * replace it with the string '[VERB]' if the word is in listOfVerbs * replace it with the string '[NOUN]' if the word is in listOfNouns returns: string, A Mad-Libs form of the story. """
Its python
THE CODE def generateForm(story, listOfAdjs, listOfNouns, listOfVerbs): """ story: a string containing sentences listOfAdjs: a list of valid adjectives listOfNouns: a list of valid nouns listOfVerbs: a list of valid verbs For each word in story that is in one of the lists, * replace it with the string '[ADJ]' if the word is in listOfAdjs * replace it with the string '[VERB]' if the word is in listOfVerbs * replace it with the string '[NOUN]' if the word is in listOfNouns returns: string, A Mad-Libs form of the story. """ s = story.split() #splits on whitespace only for i in range(len(s)): if s[i] in listOfAdjs: s[i] = '[ADJ]' elif s[i] in listOfNouns: s[i] = '[NOUN]' elif s[i] in listOfVerbs: s[i] = '[VERB]' return ' '.join(s) THE TEST listOfAdjs = ['adj1', 'adj2', 'adj3'] listOfNouns = ['noun1', 'noun2', 'noun3'] listOfVerbs = ['verb1', 'verb2', 'verb3'] story = "Once upon a noun1 verb2 adj3 I had a noun2 verb3 adj1 and then noun3" mad = generateForm(story, listOfAdjs, listOfNouns, listOfVerbs) print(mad) THE OUTPUT Once upon a [NOUN] [VERB] [ADJ] I had a [NOUN] [VERB] [ADJ] and then [NOUN]
Thank you @msmithhnova
Join our real-time social learning platform and learn together with your friends!