This course will become read-only in the near future. Tell us at community.p2pu.org if that is a problem.

Build a simple MadLib


Learn how to build a simple MadLib game using the "Roses are Red" poem.

1. Open Wing IDE and create a new file. If you don't know how, look around until you find the icon to click.

2. Type the following in the upper-left corner:

adjective1 = raw_input("Tell me an adjective, and click enter. ")
noun1 = raw_input("Tell me a noun (plural), and click enter. ")
noun2 = raw_input("Tell me another noun, and click enter. ")
adjective2 = raw_input("Tell me an another adjective, and click enter. ")

print "Roses are " + adjective1
print noun1 + " are blue"
print noun2 + " is " + adjective2
print "And so are you!"


3. Click the green "play" arrow and play your game in the lower-right corner.

4. If it didn't work, look carefully at the code above to see if your code has any errors. Find the errors and fix them.

5. Add a title to your poem and make it print out above the poem.

6. Add a space between your title and the rest of the poem.

7. Copy and paste your code into the discussion area below.

Task Discussion


  • Fer said:

    # -*- coding: iso-8859-15 -*-

    adjective1 = raw_input("Tell me an adjective, and click enter. ")
    noun1 = raw_input("Tell me a noun (plural), and click enter. ")
    noun2 = raw_input("Tell me another noun, and click enter. ")
    adjective2 = raw_input("Tell me an another adjective, and click enter. ")

    print "\n\nThe best ever written poem!\n"
    print "Roses are " + adjective1
    print noun1 + " are blue"
    print noun2 + " is " + adjective2
    print "And so are you!"

    on Nov. 7, 2013, 4:49 a.m.
  • v4lent1na said:

    Here:

    adjective1 = raw_input("Tell me an adjective, and click enter. ")
    noun1 = raw_input("Tell me a noun (plural), and click enter. ")
    noun2 = raw_input("Tell me another noun, and click enter. ")
    adjective2 = raw_input("Tell me an another adjective, and click enter. ")
    title = 'White Flower'
    print title
    print "Daisies are " + adjective1
    print noun1 + " are white"
    print noun2 + " is " + adjective2
    print "And so are you!"

    on Sept. 19, 2013, 12:28 p.m.
  • Joseortiz87 said:

     

    adjective1 = input("Tell me an adjective, and click enter. ")
    noun1 = input("Tell me a noun (plural), and click enter. ")
    noun2 = input("Tell me another noun, and click enter. ")
    adjective2 = input("Tell me an another adjective, and click enter. ")
    title = "\n POEM \n"
     
    print(title)
    print("Roses are " + adjective1)
    print(noun1 + " are blue")
    print(noun2 + " is " + adjective2)
    print("And so are you!")
    on May 7, 2013, 12:57 p.m.
  • Joseortiz87 said:

     

    adjective1 = input("Tell me an adjective, and click enter. ")
    noun1 = input("Tell me a noun (plural), and click enter. ")
    noun2 = input("Tell me another noun, and click enter. ")
    adjective2 = input("Tell me an another adjective, and click enter. ")
    title = "\n POEM \n"
     
    print(title)
    print("Roses are " + adjective1)
    print(noun1 + " are blue")
    print(noun2 + " is " + adjective2)
    print("And so are you!")
    on May 7, 2013, 12:55 p.m.
  • Wouter Tebbens said:

    adjective1 = raw_input("Tell me an adjective, and click enter. ")

    noun1 = raw_input("Tell me a noun (plural), and click enter. ")

    noun2 = raw_input("Tell me another noun, and click enter. ")

    adjective2 = raw_input("Tell me an another adjective, and click enter. ")

    title= "\nVariable roses\n"

    print title

    print "Roses are " + adjective1

    print noun1 + " are blue"

    print noun2 + " is " + adjective2

    print "And so are you!"

    on March 26, 2013, 5:38 a.m.
  • drediamond said:

     

    adjective1 = raw_input("Tell me an adjective, and click enter. ")
    noun1 = raw_input("Tell me a noun (plural), and click enter. ")
    noun2 = raw_input("Tell me another noun, and click enter. ")
    adjective2 = raw_input("Tell me an another adjective, and click enter. ")
    title = 'Roses Stink/n'
    print title
    print "Roses are " + adjective1
    print noun1 + " are blue"
    print noun2 + " is " + adjective2
    print "And so are you!"
    on Dec. 12, 2012, 2:24 a.m.
  • Mars83 said:

     

    adjective1 = raw_input("Tell me an adjective, and click enter. ")
    noun1 = raw_input("Tell me a noun (plural), and click enter. ")
    noun2 = raw_input("Tell me another noun, and click enter. ")
    adjective2 = raw_input("Tell me an another adjective, and click enter. ")
    print "Of roses and you\n"
    print "Roses are " + adjective1
    print noun1 + " are blue"
    print noun2 + " is " + adjective2
    print "And so are you!"
    on Sept. 11, 2012, 3:27 p.m.
  • saravanan said:

    adjective1 = input("Tell me an adjective, and click enter. ")
    noun1 = input("Tell me a noun (plural), and click enter. ")
    noun2 = input("Tell me another noun, and click enter. ")
    adjective2 = input("Tell me an another adjective, and click enter. ")
    print("\n")
    print("Saravanan's Poem\n")
    print("Roses are",adjective1)
    print(noun1," are blue")
    print(noun2," is",adjective2)
    print("And so are you!")
     

    on Sept. 10, 2012, 3:10 a.m.
  • Rob said:

     

    adjective1 = raw_input("Tell me an adjective, and click enter. ")
    noun1 = raw_input("Tell me a noun (plural), and click enter. ")
    noun2 = raw_input("Tell me another noun, and click enter. ")
    adjective2 = raw_input("Tell me an another adjective, and click enter. ")
    print "\n"
    print "Roses are....and so are you!"
    print"\n"
    print "Roses are " + adjective1
    print noun1 + " are blue"
    print noun2 + " is " + adjective2
    print "And so are you!"
    on Aug. 26, 2012, 3:05 p.m.
  • amryfitra said:

     

    __author__ = 'amryfitra'
     
     
    adjective1 = input("Tell me an adjective, and click enter. : ")
    noun1 = input("Tell me a noun (plural), and click enter. : ")
    noun2 = input("Tell me another noun, and click enter. : ")
    adjective2 = input("Tell me an another adjective, and click enter. :")
     
    print ("Roses are " + adjective1)
    print (noun1 + " are blue")
    print (noun2 + " is " + adjective2)
    print ("And so are you!")
    on Aug. 21, 2012, 10:04 a.m.
  • ionut.vlasin said:

    on July 11, 2012, 3:40 a.m.
  • iamomnipotent said:

     

    adjective1 = raw_input("Tell me the weirdest adjective u can think of!")
    adjective2 = raw_input("Great job! Now let's move on to the next adj.")
    name1 = raw_input("D'ya know anything about a famous person?")
    verbwithing1 = raw_input("Tell me what is s/he doing! Use a verb plus ing.")
     
    print ("OK then! Now let's see what is the story u made.")
    print ("The weather today is so fucking " + adjective1)
    print ("I get into a " + adjective2 + "house!")
    print ("Wow!! See who is " + verbwithing1 + " here----" + name1 + "!!!") 
    on July 7, 2012, 10:29 a.m.
  • Lisa said:

    This is my first Python program, so I didn't get too fancy. It is nice to see what other people did.

    first_name = raw_input("Welcome! What's your name? Type it and click enter. ")
    print "Hello " + first_name + ". You humans are lucky. I don't have a name. Let's play a game."

    adjective1 = raw_input("Tell me an adjective, and click enter. ")
    noun1 = raw_input("Tell me a noun (plural), and click enter. ")
    noun2 = raw_input("Tell me another noun, and click enter. ")
    adjective2 = raw_input("Tell me an another adjective, and click enter. ")

    print first_name + " 's Wacky Poem"
    print ""
    print "Roses are " + adjective1
    print noun1 + " are blue"
    print noun2 + " is " + adjective2
    print "And so are you!"

    on March 13, 2012, 5:55 p.m.
  • dvdjaco said:

    Thanks to gnuisance, Justin and the rest for the pointers in using title() and string.capwords()

    import string
    
    # Ask the user for input
    adjective1 = raw_input("Give me an adjective! ")
    noun1 = raw_input("Give me a noun (plural)! ")
    noun2 = raw_input("Give me another noun! ")
    adjective2 = raw_input("Give me another adjective and brace yourself... ")
    
    # Print the poem
    print ""
    print string.capwords("A poem with " + noun1)
    print ""
    print "Roses are " + adjective1
    print noun1.capitalize() + " are blue"
    print noun2.capitalize() + " is " + adjective2
    print "And so are you!"

    on Feb. 21, 2012, 7:26 p.m.
  • Justin Ward said:

    I like that people used some extra commands to improve their code.  I have never used python before today so strating to see some additional commands and where they fit in was great.  I was originally going to add the line after the title using print "" but using \n seems more elegant.

    Using capitalize() and lower() to ensure the words fit into the poem with the correct case is handy.
     
    I also liked the concept of title() however found limitations with how it handles apostrophes.  However this was also good as it prompted me to look for a solution and learn about using string.capwords instead.  For anyone wanting to use this command if you also want to use \n they will need to be outside the command. e.g:
     
    import string
    print "\n", string.capwords("Roses Are " + first_name + "'s best friend?!?!"), "\n"
     
    Brylie's use of an if statement and Landon's demonstration of functions will no doubt come in handy furth down the track.
     
    Anyway enough of me babbling on.....here is my code:
     
    #Gather user input
    first_name = raw_input("Tell me your first name, and press enter. ").capitalize()
    adjective1 = raw_input("Tell me an adjective, and press enter. ").lower()
    noun1 = raw_input("Tell me a noun (plural), and press enter. ").capitalize()
    noun2 = raw_input("Tell me a singular noun, and press enter. ").capitalize()
    adjective2 = raw_input("Tell me an another adjective, and press enter. ").lower()
     
    #Display title
    print "\nRoses Are " + first_name + "'s Best Friend?!?!\n"
     
    #Display poem with users input
    print "Roses are " + adjective1
    print noun1 + " are blue"
    print noun2 + " is " + adjective2
    print "And so are you!"
    on Feb. 17, 2012, 8:59 p.m.
  • Judith Elaine Bush said:

    I'm appreciating the value of looking at the comments and seeing everyone else's work. I appreciate the response that fixes the case of the input, mostly.

     

     

     

    # Assume the user prefers their name with the case as entered.

    name      = raw_input('Type in your name and complete with the return key: ')

    print 'We now have your name on record as ' + name + '.'

    # Correct case in the mad lib input to support conventional capitalization of the first letter of each line.

    adj1      = raw_input("Type in an adjective and complete with the return key: ").lower()

    noun1     = raw_input("Type in a noun (plural) and complete as above: ").capitalize()

    noun2     = raw_input("Type in another noun and as above: ").capitalize()

    adj2      = raw_input("Type in an another adjective etc: ").lower()

    title     = raw_input("Type in a phrase: ").title()  

    print title +'\nby judielaine and ' + name + '\n'

    print "Roses are "+ adj1 +","

    print noun1 +" are blue,"

    print noun2 +" is "+ adj2+","

    print "And so are you!"

    on Feb. 1, 2012, 8:36 p.m.
  • gnuisance said:

    adjective1 = raw_input("Tell me an adjective, and click enter. ")
    noun1 = raw_input("Tell me a noun (plural), and click enter. ").capitalize()
    noun2 = raw_input("Tell me another noun, and click enter. ").capitalize()
    adjective2 = raw_input("Tell me an another adjective, and click enter. ")


    print 'wing it'.title(), '\n'
    print "Roses are " + adjective1
    print noun1 + " are blue"
    print noun2 + " is " + adjective2
    print "And so are you!"

    on Jan. 30, 2012, 7:07 p.m.

    Justin Ward said:

    I noticed your use of .title() but came across an issue with it.  If you have an apostrophe in your title in incorrectly capitalizes the letter after the apostrophe. e.g:

    print "Roses are a man's best friend?!?!"

    displays as:

    Roses Are A Man'S Best Friend?!?!

    Another way to do this is using string.capwords e.g:

     

    import string
    print string.capwords("Roses are a man's best friend?!?!")
    on Feb. 17, 2012, 8:41 p.m. in reply to gnuisance
  • Shannon said:

     

    #mad lib generator
    #let the user input parts of speech for use in a madlib
    adj1 = str (input ('Let\'s mad lib!; give me and adjective and press enter. '))
    n1 = str (input ('Okay, now a plural noun. '))
    n2 = str (input ('A singular noun. '))
    adj2 = str (input ('Another adjective, and brace yourself for hilarity. '))
     
    #title
    print ('\nDon\'t be caught in a lurch this Valentine\'s Day!\n')
     
    #combine the input words with text
    print ('roses are ' + adj1 + '.')
    print (n1 + ' are blue.')
    print (n2 + ' is ' + adj2 + '.')
    print ('And so are you!')
     
    I admired a previous poster's capitalizing input to match the context of the poem. Does anyone have suggestions for an optimum strategy for finding desired commands and syntax that you think might exist? I'm using Python 3.2.
     
    If you say 'Google it,' I'm gonna be let down.
    on Jan. 20, 2012, 1:06 p.m.
  • Captain_Ahab said:

     

    adjective1=input('Tell me an adjective, and click enter.\n')
    noun1=input('Tell me a noun (plural), and click enter.\n')
    noun2=input('Tell me another noun (plural), and click enter.\n')
    adjective2=input('Tell me another adjective, and click enter.\n')
    print('Uh oh, its crazy mad lib time\n')
    print('Roses are '+ adjective1)
    print(noun1+' are blue')
    print(noun2 +" is " +adjective2)
    print('AND SO ARE YOU!')
    on Jan. 18, 2012, 7:17 a.m.
  • Ken Doman said:

    # Madlib program
    # step 1: request the words

    adjective1 = raw_input("Tell me an adjective, and click enter. ")
    noun1 = raw_input("Tell me a noun (plural), and click enter. ")
    noun2 = raw_input("Tell me another noun, and click enter. ")
    adjective2 = raw_input("Tell me an another adjective, and click enter. ")

    # step 2: print the poem
    print
    print "Roses are...er...um..."
    print
    print "Roses are " + adjective1
    print noun1.capitalize() + " are blue"
    print noun2.capitalize() + " is " + adjective2
    print "And so are you!"

    on Jan. 13, 2012, 3:18 p.m.