import random def generate_mad_lib(): templates = [ "The {adjective} {noun} {verb} over the {adjective} {noun}.", "In a {adjective} land, a {noun} and a {noun} went on a {adjective} adventure.", "The {noun} {verb} {adverb} while the {adjective} {noun} watched in amazement." ] parts_of_speech = { "adjective": ["brave", "mysterious", "colorful", "gigantic", "tiny"], "noun": ["wizard", "dragon", "knight", "castle", "forest"], "verb": ["flew", "danced", "sang", "fought", "explored"], "adverb": ["quickly", "silently", "gracefully", "fiercely", "carefully"] } template = random.choice(templates) for part in parts_of_speech: while "{" + part + "}" in template: template = template.replace("{" + part + "}", random.choice(parts_of_speech[part]), 1) return template # Example usage print(generate_mad_lib())