How to Create a Mad Libs Game Prompt in Python?

Estimated read time 2 min read

To create a Mad Libs game prompt in Python, you can use the input() function to prompt the user for different types of words, such as nouns, verbs, adjectives, and so on. Here’s an example of how to create a Mad Libs game prompt in Python:

# define the story template
story = "One day, I was {verb} in the {noun} when suddenly, a {adjective} {noun} appeared!"

# prompt the user for input
verb = input("Enter a verb: ")
noun1 = input("Enter a noun: ")
adjective = input("Enter an adjective: ")
noun2 = input("Enter another noun: ")

# replace the placeholders in the story with the user's input
mad_libs = story.format(verb=verb, noun=noun1, adjective=adjective, noun=noun2)

# print the resulting story
print(mad_libs)

In this example, we define a story template with placeholders for the words the user will input. We then use the input() function to prompt the user for a verb, a noun, an adjective, and another noun. The user’s input is stored in variables.

We then use string formatting to replace the placeholders in the story template with the user’s input. Finally, we print the resulting story.

You can modify this example to include more placeholders and to create more complex stories. You could also use random words from a word bank or a list of pre-defined words instead of user input to create the Mad Libs story.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply