Project 4: Madlibs

In this project you'll take user input to create a Madlib generator. Haven't heard of Madlibs? It's a word game:

Madlibs are like templates. Here's a PDF of some typical Madlibs:

One person knows the template and asks for particular types of words (e.g. noun, adjective). The player that picks the words doesn't know the template. At the end the template is read with the randomly picked words and hilarity ensues.


You will turn in exercises 11 through 14 with this project.

A Madlib Generator

You program will be called with one command line input. The input will be the Madlib template. The template will have three missing pieces, a noun a verb and an adjective. Here's an example of how your program will be called:

python3.6 ./ 'I like to {verb} {adjective} {noun}.'

Once called your program must prompt the user for the three missing words. The words will always be noun, verb and adjective and you should prompt the user in that order:

python3.6 ./ 'I like to {verb} {adjective} {noun}.'
Please enter a noun:
Please enter a verb:
Please enter an adjective:

After gathering three words your program prints the completed Madlib. For example if the user entered the words, “word”, “ran” and “rock” the program execution would look like this:

python3.6 ./ 'I like to {verb} {adjective} {noun}.'
Please enter a noun: word
Please enter a verb: ran
Please enter an adjective: rock
I like to word ran rock


  1. Your program must have the required docstrings
  2. You must take exactly one command line argument
  3. You must prompt the user for three inputs (verb, adjective, noun) in order
  4. You must print the completed madlib after taking input
  5. Your project must be in a file named

Web-Based Madlib (Advanced)

The advanced project for this week is the same Madlib generator, but on the web. The requirements are:

  1. The web-based madlib gets the madlib input from an environment variable named MADLIB
  2. Use a web form to input the verb, adverb and noun
  3. Display the completed Madib upon submission of the form

Your web-Madlib generator will be executed like this:

$ export MADLIB='I like to {verb} {adjective} {noun}.' 
$ python3.6 

Starter Code

from flask import Flask, request 
app = Flask(__name__)
html_form = '''
        <title>Simple Form</title>
        <form action="/result" method="post">
          <input type="text" name="noun"><br>
          <input type="text" name="verb"><br>
          <input type="text" name="adjective"><br><br>
          <input type="submit" value="Submit">
@app.route('/', methods=['GET'])
def do_form():
    return html_form
@app.route('/result', methods=['POST'])
def do_table():
    user_noun = request.form['noun']  
    user_verb = request.form['verb']  
    user_adjective = request.form['adjective']  
    return f'You said noun: {user_noun} verb: {user_verb} adjective: {user_adjective}' 
if __name__ == '__main__' :'', port=8080)


  • All files must have header comments.
  • Submit your program in a file called
  • The project has the following requirements:
    • You must take three inputs (noun, verb, adjective)
    • You must print the completed madlib on a line by itelf.
    • If there's an error you must output an error message that contains the word “sorry”
  • If you do the web-based version submit the following:
    • A directory called project4
      • Your program in project4/
      • Your templates in project4/templates
      • Your templates can have any names you choose
    • Your program must use the 'MADLIB' environment variable (not the command line)


  • 5 points for the exercises
  • 5 points for a correct submission (filenames, comments, etc)
  • 10 points for the correctness of your program.