programming-fundamentals
  • Introduction
  • Lesson 1
    • Writing Your First Program
    • Data Types
    • Built In Functions
    • If Statements
    • Using Git and Github
    • Primer
    • Questions
    • Tip Calculator
    • GPA Calculator (optional)
  • Lesson 2
    • Modules
    • Lists
    • Data Structures
    • More On Data Structures
    • Questions
    • Madame Zamad
    • Mad Libs
  • Lesson 3
    • While Loops
    • For Loops
    • Loops and Lists
    • Special Commands
    • Questions
    • TODO List
    • Fibonacci (optional)
  • Lesson 4
    • Functions
    • More Functions
    • Error Handling
    • File I/O
    • Questions
    • Sudoku
Powered by GitBook
On this page
  • Setup
  • Requirements
  • Imports
  • Dictionaries and Lists

Was this helpful?

  1. Lesson 2

Mad Libs

PreviousMadame ZamadNextWhile Loops

Last updated 5 years ago

Was this helpful?

Hopefully you have tried a few mad-libs in your time. If you haven't, the idea is to fill in the blanks to a short story with the appropriate language parts (e.g. verb, noun, etc). When you are finished it is often a funny story. You will be implementing the part that randomly retrieves language parts for the main mad libs program.

Setup

Fork the following repository and clone your copy (if you haven't already for this lesson).

Open languageparts.py in your text editor.

For this assignment you are not writing the main program but are writing a module that the main program will use. Run the program using:

python mad-libs.py

Requirements

Imports

  • use the random module to randomly select items from lists

Dictionaries and Lists

  • create a dictionary with at least the following language parts: noun, verb,

    adjective. Each language part will have a list of words that match that type.

    You may add more language parts but you must have the minimum set listed

    above.

  • make sure the given language part is in the dictionary before trying to get

    the parts.

  • randomly select an item from the list associated with the given language part.

Mad Libs