Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for How to build a Madlib Game in Python
Rishabh Singh ⚡
Rishabh Singh ⚡

Posted on

     

How to build a Madlib Game in Python

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 useinput() function as always.

noun=input("Noun:")adj=input("Adjective:")noun2=input("Noun:")
Enter fullscreen modeExit 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 hisnoun for two years, he grewadj and tried to sell it to anoun2 in Mumbai, but was caught...

Now, all we have to do is to, replace the missing spots with our variables. Let's do that usingf-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 modeExit 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 considerBuying 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 onTwitter,LinkedIn &GitHub. Or you can also post a comment/discussion & I will try my best to help you :D

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

💻 Full Stack Engineer | 🔆 Freelance UI/UX Designer | ⚡ Ambassador/Lead @microsoft @codecademy @codeforcauseIn | 👨‍🏫Teaching + ✍️Writing + 🛠Building
  • Location
    Mumbai, India
  • Education
    University of Mumbai
  • Joined

More fromRishabh Singh ⚡

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp