GameDevelopmentSonnet3.5-AIPP / mad_lib_generator.py
awacke1's picture
Create mad_lib_generator.py
6d1d9f0 verified
raw
history blame contribute delete
923 Bytes
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())