-
Notifications
You must be signed in to change notification settings - Fork 566
Expand file tree
/
Copy path5-challenge-wax-poetic.py
More file actions
118 lines (102 loc) · 2.37 KB
/
5-challenge-wax-poetic.py
File metadata and controls
118 lines (102 loc) · 2.37 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# 9.5 - Challenge: Wax Poetic
# Solution to challenge
# Generate a random poem based on a set structure
import random
noun = [
"fossil",
"horse",
"aardvark",
"judge",
"chef",
"mango",
"extrovert",
"gorilla",
]
verb = [
"kicks",
"jingles",
"bounces",
"slurps",
"meows",
"explodes",
"curdles",
]
adjective = [
"furry",
"balding",
"incredulous",
"fragrant",
"exuberant",
"glistening",
]
preposition = [
"against",
"after",
"into",
"beneath",
"upon",
"for",
"in",
"like",
"over",
"within",
]
adverb = [
"curiously",
"extravagantly",
"tantalizingly",
"furiously",
"sensuously",
]
def make_poem():
"""Create a randomly generated poem, returned as a multi-line string."""
# Pull three nouns randomly
n1 = random.choice(noun)
n2 = random.choice(noun)
n3 = random.choice(noun)
# Make sure that all the nouns are different
while n1 == n2:
n2 = random.choice(noun)
while n1 == n3 or n2 == n3:
n3 = random.choice(noun)
# Pull three different verbs
v1 = random.choice(verb)
v2 = random.choice(verb)
v3 = random.choice(verb)
while v1 == v2:
v2 = random.choice(verb)
while v1 == v3 or v2 == v3:
v3 = random.choice(verb)
# Pull three different adjectives
adj1 = random.choice(adjective)
adj2 = random.choice(adjective)
adj3 = random.choice(adjective)
while adj1 == adj2:
adj2 = random.choice(adjective)
while adj1 == adj3 or adj2 == adj3:
adj3 = random.choice(adjective)
# Pull two different prepositions
prep1 = random.choice(preposition)
prep2 = random.choice(preposition)
while prep1 == prep2:
prep2 = random.choice(preposition)
# Pull one adverb
adv1 = random.choice(adverb)
if "aeiou".find(adj1[0]) != -1: # First letter is a vowel
article = "An"
else:
article = "A"
if "aeiou".find(adj3[0]) == 1: # First letter of adj3 is a vowel
article2 = "An"
else:
article2 = "A"
# Create the poem
poem = (
f"{article} {adj1} {n1}\n\n"
f"{article} {adj1} {n1} {v1} {prep1} the {adj2} {n2}\n"
f"{adv1}, the {n1} {v2}\n"
f"the {n2} {v3} {prep2} {article2.lower()} {adj3} {n3}"
)
return poem
poem = make_poem()
print(poem)