Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Syamantak

  • 3 years ago

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. """

  • This Question is Closed
  1. Syamantak
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Its python

  2. msmithhnova
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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]

  3. Syamantak
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thank you @msmithhnova

  4. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy