AI Features

Solution: Mad Lib Generator

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")