DEV Community

loading...
Cover image for How to build a Madlib Game in Python

How to build a Madlib Game in Python

mindninjax profile image Rishabh Singh ⚡ ・2 min read

Hey folks, let's build a Madlibs Game in Python!

How does it work?

Alt Text

A Madlib game is a super simple game where we put random nouns and adjectives into a sentence.

In our game, the player will be asked to enter two different nouns & one adjective of their choice.

Both nous & adjectives will be stored in a separate variable and then they will be concatenated in a string.

And the final string will be printed on the screen.

Sounds fun right? Let's build it!

Let's Code

Alright, so the first thing we are gonna do is to ask the user to enter 2 nouns and an adjective. We will use input() function as always.

noun = input("Noun: ")
adj = input("Adjective: ")
noun2 = input("Noun: ")
Enter fullscreen mode Exit fullscreen mode

Awesome now we will simply put them into our sentence.

You can use any appropriate sentence of your choice. You can also Google for fun Madlib sentences. Please note that other sentences may require you to add or remove nouns and adjectives... But that shouldn't be a problem since this tutorial is super easy to follow.

For this tutorial, we are going to make use of this silly sentence -

After hiding the painting in his noun for two years, he grew adj and tried to sell it to a noun2 in Mumbai, but was caught...

Now, all we have to do is to, replace the missing spots with our variables. Let's do that using f-strings.

print(f"After hiding the painting in his {noun} for two years, he grew {adj} and tried to sell it to a {noun2} in Mumbai, but was caught...")
Enter fullscreen mode Exit fullscreen mode

There we go!

We did it! Easy and short right!

Feel free to customize it and make it more fun to play with your friends.

Source Code

You can find the complete source code of this project here -

mindninjaX/Python-Projects-for-Beginners

Support

Thank you so much for reading! I hope you found this beginner project useful.

If you like my work please consider Buying me a Coffee so that I can bring more projects, more articles for you.

https://dev-to-uploads.s3.amazonaws.com/i/5irx7eny4412etlwnc64.png

Also if you have any questions or doubts feel free to contact me on Twitter, LinkedIn & GitHub. Or you can also post a comment/discussion & I will try my best to help you :D

Discussion (0)

pic
Editor guide