Skip to content

Instantly share code, notes, and snippets.

@Elvmeen
Created April 14, 2025 21:25
Show Gist options
  • Select an option

  • Save Elvmeen/46e32948f848b18a612312053084b49c to your computer and use it in GitHub Desktop.

Select an option

Save Elvmeen/46e32948f848b18a612312053084b49c to your computer and use it in GitHub Desktop.
This is a MadLib Game in Pythin by Aminu M.
import random
import time
def display_welcome():
print("\n" + "=" * 50)
print("WELCOME TO THE QUIRKY MADLIB GENERATOR!".center(50))
print("=" * 50)
print("\nLet's create a hilarious story together!")
print("Just answer a few quick questions and I'll generate something absurd!")
print("-" * 50)
def get_input(prompt):
return input(f"\n{prompt}: ")
def generate_madlib():
# Story templates - each has minimal grammar questions and more fun prompts
templates = [
# Space Adventure
"""In the year {large_number}, humans discovered a new planet called {silly_word}-topia.
Captain {unusual_job_title} led the mission to explore this strange world.
Upon landing, they immediately noticed the air smelled like {favorite_food} and the ground felt like {texture}.
"This is {enthusiastic_exclamation}!" shouted the captain as they spotted a {color} alien with {number} eyes.
The alien approached them and said, "{random_phrase}!"
Everyone was surprised when the alien then started to {funny_action}.
They decided to name this new species the {adjective} {animal}s of {silly_word}-topia.""",
# Cooking Disaster
"""Famous chef {fictional_character} was attempting to break the world record for the largest {food_item} ever made.
"I'll need {large_number} pounds of {ingredient} and a {household_object} to stir it!" they declared.
The cooking show audience gasped when the chef accidentally added {disgusting_substance} instead of salt.
"No problem!" the chef said, "{confident_phrase}!"
To fix the disaster, they decided to {outrageous_solution}.
The judges took one bite and immediately {weird_reaction}.
The dish was described as "{adjective} with notes of {strange_flavor}."
Despite everything, it won first prize in the category of Most {superlative} Food.""",
# Superhero Mishap
"""The city was in danger when the evil {silly_villainous_title} threatened to turn everyone into {plural_noun}.
Fortunately, {made_up_name}, also known as The {adjective} {animal}, was there to save the day!
Using their superpower of extreme {unusual_skill}, they confronted the villain at the {weird_location}.
"Stop right there!" they shouted. "Or I'll be forced to {funny_threat}!"
The villain responded by throwing a giant {object} which our hero dodged by {ing_verb}.
In the end, the day was saved when {made_up_name} defeated the villain by making them {embarrassing_action}.
The mayor awarded them with a medal made of {material} and a lifetime supply of {ridiculous_item}."""
]
# Select a random template
template = random.choice(templates)
# Dictionary of prompts for user inputs
if "space adventure" in template.lower():
prompts = {
"large_number": "Enter a really big number",
"silly_word": "Make up a funny-sounding word",
"unusual_job_title": "Enter a job title that doesn't exist",
"favorite_food": "What's your favorite food",
"texture": "Name a weird texture (slimy, fluffy, etc.)",
"enthusiastic_exclamation": "Give an enthusiastic exclamation",
"color": "Name a color",
"number": "Enter a number between 1 and 100",
"random_phrase": "Type a random phrase or greeting",
"funny_action": "Name a funny action (like 'dance the macarena')",
"adjective": "Enter a funny adjective",
"animal": "Name an animal"
}
elif "cooking" in template.lower():
prompts = {
"fictional_character": "Name any fictional character",
"food_item": "Name a food item",
"large_number": "Enter a ridiculously large number",
"ingredient": "Name an unusual ingredient",
"household_object": "Name a household object",
"disgusting_substance": "Name something disgusting",
"confident_phrase": "Enter a confident catchphrase",
"outrageous_solution": "Describe an outrageous solution to a problem",
"weird_reaction": "How might someone react to terrible food",
"adjective": "Enter a strange adjective",
"strange_flavor": "Name a strange flavor",
"superlative": "Enter a superlative (Most ___)"
}
else: # superhero template
prompts = {
"silly_villainous_title": "Make up a silly villain name (like 'The Sock Snatcher')",
"plural_noun": "Enter a plural noun",
"made_up_name": "Make up a hero name",
"adjective": "Enter an adjective",
"animal": "Name an animal",
"unusual_skill": "Name an unusual skill",
"weird_location": "Name a weird location",
"funny_threat": "Make up a funny threat",
"object": "Name an object",
"ing_verb": "Enter a verb ending in 'ing'",
"embarrassing_action": "Describe an embarrassing action",
"material": "Name a material",
"ridiculous_item": "Name a ridiculous item"
}
# Collect user inputs
user_inputs = {}
print("\nI need some words from you to create your story:")
for key, prompt in prompts.items():
user_inputs[key] = get_input(prompt)
# Fill in template with user inputs
madlib = template.format(**user_inputs)
return madlib
def display_madlib(madlib):
print("\n" + "=" * 50)
print("YOUR MADLIB STORY IS READY!".center(50))
print("=" * 50 + "\n")
# Add dramatic effect by printing slowly
for char in madlib:
print(char, end='', flush=True)
time.sleep(0.01) # Adjust speed if needed
print("\n" + "=" * 50)
def play_again():
while True:
response = input("\nWant to create another MadLib? (yes/no): ").lower()
if response in ['yes', 'y']:
return True
elif response in ['no', 'n']:
return False
else:
print("Please enter 'yes' or 'no'.")
def main():
display_welcome()
playing = True
while playing:
madlib = generate_madlib()
display_madlib(madlib)
playing = play_again()
print("\nThanks for playing! Have a quirky day!\n")
if __name__ == "__main__":
main()
@Elvmeen
Copy link
Author

Elvmeen commented Apr 14, 2025

MadlibbyAminu
Sample of Output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment