Learn to Code via Tutorials on Repl.it!

← Back to all posts
Simple Madlibs tutorial in python!
Ravost

E_MADLIBS Tutorial

Make sure to Upvote, React, and Fork!


First lets start out with what we want our final text to be.

For example mine will be:

It was a beautiful day in 'city'. 'person1' was at their house watching 'tv' at 'place'. Then 'person2' 'V2' at the 'N1'. Hi, 'person2' said 'person1' come and watch TV with me! The guy on 'tv' was 'V2' in the 'N1' and fell off the 'N2'. Its the same 'V1' again. Bob and Cool-Man helped the person from the water.

You can change yours to be what you like.

Next add some inputs for your items in quotes above.

Then replace your items in the original statement, but now add curly brackets instead of the quotes.

f"It was a beautiful day in {city}. {person1} was watching {tv} at {place}. Then {person2} {V1} at the door. Hi {person2} said {person1} come and watch TV with me! The guy on {tv}was {V2} in the {N1} and fell off the {N2}. Its the same {V1} again. Bob and Cool-Man helped the person from the water."

This text is called an f-string

Print your new message.

And there you go! Finished E_Madlibs!


Bonus!

Hacks and tweaks

  • Adding an ending

Simple! Just print an ending!

  • Intro

Change for your own mad lib

  • Typewriter message

Change your original message to a varible

Import time:
import sys, time

Then a for loop:

Then checking if the string includes something

and there you go!

Thats all!
Ravost

Voters
Ravost
Comments
hotnewtop
MrVoo

I would think of this more like a template, but nice!