Homework 2-3

Formatting Strings

Mad-Lib

Practicing Kung Fu all day is tiring! You and your fellow classmates decide to unwind after a long day of training by reading legends about great warriors and playing around with Mad-Libs. In this task, you will create a program that takes in user inputs and fills out a Mad Lib that we have provided below. Strings inputted into the blanks should be formatted and inserted in a specified way.

According to Wikipedia, a Mad-Lib is a phrasal template word game where one player prompts others for a list of words to substitute for blanks in a story, before reading the – often comical or nonsensical – story aloud. The game is frequently played as a party game or as a pastime.

The goal of this assignment is to master the str.format() function by creating a Mad-Lib and inserting user inputs into the blanks. When you run the program, the program should prompt for inputs specific to the kinds of words that should be used to fill in the blanks. The program should then input these words within the Mad-Lib. Finally, the program should print out the entire Mad-Lib at the end.


Step 1: For each underlined word in the madlib below, prompt the user for the underlined phrase. For example, for noun 1 your program might look like noun_1 = input("Please input noun 1 ")

Step 2: Use string functions to format the inputs in the correct way as listed below

Step 3: Use str.format() to replace the underlined words within the Mad-Lib


Copy and paste the following paragraphs into your program. Each paragraph should be its own string. Follow the directions for each paragraph listed below.

Reminder: These paragraphs will be longer than 80 characters, which according to our style guide is the maximum number of characters allowed in a line. To prevent this, on Sublime, use View -> Ruler -> 80 to create a line at the 80 character mark. You can use \ to allow you to continue the string on the next line. If you are confused about this, check out the slides from the Sublime and Command Line help session.

Note: When you copy and paste these paragraphs into your editor, remember to replace the underlined words with the {} block.


Legend tells of a legendary noun 1 whose activity skills were the stuff of legend. He past tense verb the land in search of adjective foes. The noun 1 said nothing for his body part was full, then he past tense verb, and then he past tense verb.

He was so adjective, in fact, that his enemies would go blind from over-exposure to pure adjective ending in ness 1! … There is no charge for adjective ending in ness 1 … or adjective ending in ness 2. … It mattered not how many foes he faced, they were no match for his adjective ending in ness 3.

Never before had a animal been so adjective and so adjective. Even the most heroic heroes in all of country, the Famous Group, bowed in respect to this great master. … But hanging out would have to wait, because when you’re facing the number demons of demon geographical feature, there’s only one thing that matters and that’s Something that matters.


Note: Avoid repeating variables by using the same index to refer to each variable in str.fomrmat(). So, if a word repeats, repeat the index in the string, but only include the variable once in format().

Paragraph 1
  • Lowercase all inputted words
  • When inputting words into the paragraph, input words by parameterized input. Don't repeat variables!
  • Note that noun 1 repeats in this paragraph
Paragraph 2
  • Lowercase all inputted words
  • When inputting words into the paragraph, input words by index. Don't repeat variables!
  • Note that adjective ending in ness 1 repeats in this paragraph
Paragraph 3
  • Lowercase all inputted words, except: Capitalize the name of the famous group and the country, and Uppercase the last inputted word (Something that matters)
  • Input the words into the paragraph in any way you chose
Extra Credit

As with every homework, you are welcome to expand on the tasks above for extra credit. Below, are some potential ideas.

  • Try designing your own Madlib, utilizing various properties of str.format()
  • Have a couple of your friends use your program and attach their resulting paragraphs to your submission.

At the top of your assignment, please comment how many hours you worked on this assignment, people you worked with, whether you went to TA hours for help or clarification on this assignment, and how comfortable you feel with setting up a program in Python and running the program through the command line.


Make sure your submission has your name in the filename: FirstLast_HW2-3.py. “FirstLast” should be replaced with your first and last name or we will take off points. Make sure every task has been completed. Once you're done, upload and share your python file with cs0030handin@gmail.com by midnight, 3/3.