File size: 923 Bytes
6d1d9f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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())