Quantcast

A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Syamantak

  • 2 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
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Its python

  2. msmithhnova
    • 2 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
    • 2 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

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.