Problem of the Day
A new programming or logic puzzle every Mon-Fri

Mad Libs

MONDAY!

Today's problem is a fun one. The goal is to come up with a story that has some blanks in it. Then prompt the user for different types of words (adjective, noun, etc) to fill out the story. For bonus points validate that the word for each slot is of the correct type (can make it as complicated or simple as you'd like).

Permalink: http://problemotd.com/problem/mad-libs/

Comments:

  • David - 9 years ago

    A quick and dirty version in python, since there are not yet any others.

    print "As with a normal madlib, it is left up to the correct type of word and provide real words."
    print "Barring absurdist humor, this will provide the best results."
    
    listofrequests = ["adjective", "adjective", "noun"]
    listofwords = []
    
    for wordtype in listofrequests:
        listofwords.append(raw_input(wordtype + " >"))
    
    paragraph = "I am generating a " + listofwords[0] + " string using the " + listofwords[1] + " words I got from a(n)" + listofwords[2]
    
    print paragraph
    

    reply permalink

Content curated by @MaxBurstein