Mad Libs in Python

Mad Libs in Python

How to Make Your Own Mad Libs Game with Python

Do you love playing Mad Libs? If you do, then you will enjoy creating your own Mad Libs game using Python language. In this blog, I will show you how to make a fun and interactive game that will generate hilarious stories based on the words you enter. You will also learn some basic concepts of Python programming along the way. Ready to get started? Let’s go!

What is Mad Libs?

Mad Libs is a word game where one player prompts another player to fill in the blanks of a story with different parts of speech, such as nouns, verbs, adjectives, etc. The result is usually a silly and nonsensical story that makes everyone laugh. Mad Libs was invented by Leonard Stern and Roger Price in 1953, and since then it has become a popular party game and a source of inspiration for many shows and cartoons.

madlibs

Create a Mad Libs story in Python

  1. Write a story template with some blanks for the words you want the player to enter or you could just copy-paste a mad libs story from online as I did.🤪 You can use any text editor or IDE to write your code.

  2. Use the input() function to ask the player to enter the words for each blank. You can assign each input to a variable with a descriptive name. For example:

    adjective1 = input("Enter an adjective: ")
    noun1 = input("Enter a noun: ")
    verb_past = input("Enter a verb, past tense: ")
    adverb = input("Enter an adverb: ")
    adjective2 = input("Enter another adjective: ")
    noun2 = input("Enter another noun: ")
  1. Use the print() function to display the final story with the words inserted in the blanks. You can use string concatenation (+) or string formatting (f-strings) to combine the variables and the text.

  2. Run your code and create multiple funny stories with your friends. You can enter any words you like and see how they change the story.

Here’s an example:

madlibs1

madlibs2

Congratulations! You have just created your own Mad Libs game using Python language. You can try different story templates and words to make your game more fun and creative. You can also add more features to your game, such as using random.choice() function to pick a random story from a list.

I hope you enjoyed this blog and learned something new. If you want to learn more about Python programming, you can check out my other blogs. Happy coding!

Nirooba
comments powered by Disqus