Exercise 02: Mad Libs

You are going to create a simple Mad Lib generator. A Mad Lib is a word game using a short story where certain elements of the story are intentionally left missing. Each missing element is identified with a part of speech, such as noun, verb, adjective, etc. and to be filled in by the reader. For example:

Yesterday [proper noun 1] decided to read a book about [plural noun] because they were feeling [emotion]. [proper noun 1] put on their [clothing item] went to the [place] to relax with their book.

Inserting random words based on the categories above, we might have a story like:

Yesterday Mary decided to read a book about computers because they were feeling anxious. Mary put on their hat went to the park to relax with their book.

This exercise is designed to introduce you to:

Setup

  1. In your cs102 folder, create a folder named ex02 for this assignment
  2. Open Thonny and ensure that you already have a code editing tab (usually it says <untitled>)
    • If you do not have an editing tab, press the white paper icon to create one
  3. Press the blue floppy disk icon to save your file. Make sure name the file madlib.py and save it in your ex02 folder

Assignment

You will write a short Mad Lib story (two to three sentences) that requires at least five pieces of information to complete the story. The information will be stored in five separate variables, merged into a coherent story via a Python f-string, and displayed using the print function. You can use information repeatedly in the story so it makes sense (e.g. like using Mary’s name twice in the example above), but each of the five variables should hold unique information (e.g. don’t do food1, food2, etc.). Make sure to name your variables such that people know what type of information to insert into the respective position within your story (e.g. noun, name, food, verb, etc.).

Submission

Right click your assignment folder and choose compress on MacOS or Compress to ZIP file on Windows. Upload the zip file to the matching Moodle assignment to submit your work.

Grading

You will earn up to 3 points for this exercise, broken down as follows: