Search⌘ K
AI Features

Solution: Mad Lib Generator

Explore how to create a Mad Lib generator function in Python that takes a noun, verb, and adjective as inputs to build sentences. Understand function definition, parameter use, and how to call functions, enhancing your coding skills with practical examples.

We'll cover the following...

This program defines a function that creates a fun sentence using the words you give it.

  • def madlib(noun, verb, adjective): defines a function named madlib that takes three inputs (called parameters): a noun, a verb, and an adjective.

  • Inside the function, the print() statement combines these words to make a sentence.

  • When you call the function with madlib("cat", "dance", "silly"), the words fill in those spots:

    • noun"cat"

    • verb"dance"

    • adjective"silly"

Python
def madlib(noun, verb, adjective):
print("The", adjective, noun, "decided to", verb, "all day.")
madlib("cat", "dance", "silly")