Categories:

Mad Libs Project via Python

Task

A simple project you can do to test and see if you understand how to use things like a “while” loop or how to collect a user’s input is by doing something like a “mad libs” task. Mad Libs is a phrasal template word game that consists of one player prompting others for a list of words to substitute for blanks in a story before reading aloud. The game is frequently played as a party game or as a pastime.

For this project, feel free to add, subtract, or modify the code to help maximize your learning.

Source

Code:

# declare variable
madlib_loop = 1
# set while loop
while (madlib_loop < 10):
    # collect user inputs 
    noun = input("Select noun: ")
    pronoun = input("Select pronoun: ")
    noun_2 = input("Select a second noun: ")
    location = input("Select a location: ")
    adj = input("Select an adjective: ")
    noun_3 = input("Select a third noun: ")
    # display the outputs, utilize concactenation 
    print ("+----------------------------------------+")
    print ("Be kind to your " + noun + "- footed", pronoun)
    print ("For a duck may be somebody's " + noun_2 + ",")
    print ("Be kind to your " + pronoun + " in " + location)
    print ("Where the weather is always " + adj + ".")
    print ()
    print ("You may think that is this the " + noun_3 + ",")
    print ("Well it is.")
    print ("+----------------------------------------+")
    #
    madlib_loop = madlib_loop + 1

Output:

Select noun: fruit
Select pronoun: Bob
Select a second noun: vegetable
Select a location: LA
Select an adjective: loud
Select a third noun: drink
+----------------------------------------+
Be kind to your fruit- footed Bob
For a duck may be somebody's vegetable,
Be kind to your Bob in LA
Where the weather is always loud.

You may think that is this the drink,
Well it is.
+----------------------------------------+
Select noun:

For more information

If you seek to learn more about Python, please visit Python’s official documentation.