Mad Libs Game using Python














































Mad Libs Game using Python



Mad Libs Game using Python 

Mad Libs is a phrasal template word game which consists of one player prompting others for a list of words to substitute for blanks in a story before reading aloud.


The game is frequently played as a party game or as a pastime.


Creating a Mad Libs game is simple. First we need to make a story, then we will remove some words from it and ask the other player to give alternate words. Then, we will read the story with the words the other player supplied.


The story becomes funny depending on the words the other player gave.


We will write a Mad Libs game in Python. The sample story we will use is as follows:


Roses are <color-here>.

<plural-noun> are blue.

I love <celebrity-name>.


We will ask the player the 3 blanks and based on their input we will print the story.


Save the below program in a file named 'mad_libs.py'.


color = input("Enter a color: ") pluralNoun = input("Enter a plural noun: ") celebrity = input("Enter a celebrity name: ") print() print("The story is:") print() print("Roses are {}.".format(color)) # Purple print("{} are blue.".format(pluralNoun)) # Gates print("I love {}.".format(celebrity)) # Keanu Reaves


First, we have taken the 3 blanks as inputs from the player and then we have printed the whole story after filling in the blanks with the player's input.


Run the program by entering the following command in Terminal/Command Line.


python3 mad_libs.py


A sample output will be as follows:


Enter a color: Purple Enter a plural noun: Gates Enter a celebrity name: Keanu Reaves The story is: Roses are Purple. Gates are blue. I love Keanu Reaves.


More Articles of Aniket Sharma:

Name Views Likes
Pyperclip: Installation and Working 991 2
Number Guessing Game using Python 683 2
Pyperclip: Not Implemented Error 1033 2
Hangman Game using Python 16819 2
Using Databases with CherryPy application 1676 2
nose: Working 509 2
pytest: Working 512 2
Open Source and Hacktoberfest 868 2
Managing Logs of CherryPy applications 1005 2
Top 20 Data Science Tools 684 2
Ajax application using CherryPy 799 2
REST application using CherryPy 664 2
On Screen Keyboard using Python 5532 2
Elastic Net Regression 815 2
US Presidential Election 2020 Prediction using Python 794 2
Sound Source Separation 1165 2
URLs with Parameters in CherryPy 1635 2
Testing CherryPy application 637 2
Handling HTML Forms with CherryPy 1449 2
Applications of Natural Language Processing in Businesses 511 2
NetworkX: Multigraphs 649 2
Tracking User Activity with CherryPy 1404 2
CherryPy: Handling Cookies 822 2
Introduction to NetworkX 633 2
TorchServe - Serving PyTorch Models 1306 2
Fake News Detection Model using Python 735 2
Keeping Home Routers secure while working remotely 484 2
Email Slicer using Python 2998 2
NetworkX: Creating a Graph 1111 2
Best Mathematics Courses for Machine Learning 551 2
Hello World in CherryPy 681 2
Building dependencies as Meson subprojects 979 2
Vehicle Detection System 1081 2
NetworkX: Examining and Removing Graph Elements 608 2
Handling URLs with CherryPy 537 2
PEP 8 - Guide to Beautiful Python Code 759 2
NetworkX: Drawing Graphs 624 2
Mad Libs Game using Python 645 2
Hosting Cherry applications 613 2
Top 5 Free Online IDEs of 2020 867 2
pytest: Introduction 535 2
Preventing Pwned and Reused Passwords 582 2
Contact Book using Python 2095 2
Introduction to CherryPy 547 2
nose: Introduction 505 2
Text-based Adventure Game using Python 3001 2
NetworkX: Adding Attributes 2290 2
NetworkX: Directed Graphs 1021 2
Dice Simulator using Python 562 2
Decorating CherryPy applications using CSS 834 2

Comments