Python Help The story generator the Madlibs game asks for p

Python Help

The story generator – the Mad-libs game asks for parts of speech, such a noun,
adjective, or adverb, and those words are plugged into a template to generate a
sometimes-funny story.
For this problem, write a function that plays a game of Mad-libs. Your function
(MadLib) will be given an integer parameter to select the story from a list of
story templates and will return the MadLib string with words from the user
substituted for the placeholders. You program will store the templates as strings
and ask the user for appropriate parts of speech to fill in the template based on
the given parameter.

your code when executed must parse the information out of the original string. You cannot predetermine the items to be replaced, you must write code so that the computer will search for the items to be replaced and prompt the user for the replacement strings.

For example the mad lib should be stored as a single string:

madlib = \"Two <noun-plural>, both alike in dignity, In fair <place>, where we lay our scene.\"

I Will give thumbs up for a code that follows the instructions, compiles and has a good explanation!!!

Solution

def getKeys(formatString): keyList = list() end = 0 repetitions = formatString.count(\'{\') for i in range(repetitions): start = formatString.find(\'{\', end) + 1 end = formatString.find(\'}\', start) key = formatString[start : end] keyList.append(key) return keyList
Python Help The story generator – the Mad-libs game asks for parts of speech, such a noun, adjective, or adverb, and those words are plugged into a template to

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site