awacke1 commited on
Commit
6d1d9f0
·
verified ·
1 Parent(s): 9ef2a4c

Create mad_lib_generator.py

Browse files
Files changed (1) hide show
  1. mad_lib_generator.py +26 -0
mad_lib_generator.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+
3
+ def generate_mad_lib():
4
+ templates = [
5
+ "The {adjective} {noun} {verb} over the {adjective} {noun}.",
6
+ "In a {adjective} land, a {noun} and a {noun} went on a {adjective} adventure.",
7
+ "The {noun} {verb} {adverb} while the {adjective} {noun} watched in amazement."
8
+ ]
9
+
10
+ parts_of_speech = {
11
+ "adjective": ["brave", "mysterious", "colorful", "gigantic", "tiny"],
12
+ "noun": ["wizard", "dragon", "knight", "castle", "forest"],
13
+ "verb": ["flew", "danced", "sang", "fought", "explored"],
14
+ "adverb": ["quickly", "silently", "gracefully", "fiercely", "carefully"]
15
+ }
16
+
17
+ template = random.choice(templates)
18
+
19
+ for part in parts_of_speech:
20
+ while "{" + part + "}" in template:
21
+ template = template.replace("{" + part + "}", random.choice(parts_of_speech[part]), 1)
22
+
23
+ return template
24
+
25
+ # Example usage
26
+ print(generate_mad_lib())