Skip to content

Clean-up Wax Poetic challenge solution #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions ch09-lists-tuples-and-dictionaries/5-challenge-wax-poetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Generate a random poem based on a set structure

from random import choice
import random

noun = [
"fossil",
Expand Down Expand Up @@ -57,54 +57,57 @@
def make_poem():
"""Create a randomly generated poem, returned as a multi-line string."""
# Pull three nouns randomly
n1 = choice(noun)
n2 = choice(noun)
n3 = choice(noun)
n1 = random.choice(noun)
n2 = random.choice(noun)
n3 = random.choice(noun)
# Make sure that all the nouns are different
while n1 == n2:
n2 = choice(noun)
n2 = random.choice(noun)
while n1 == n3 or n2 == n3:
n3 = choice(noun)
n3 = random.choice(noun)

# Pull three different verbs
v1 = choice(verb)
v2 = choice(verb)
v3 = choice(verb)
v1 = random.choice(verb)
v2 = random.choice(verb)
v3 = random.choice(verb)
while v1 == v2:
v2 = choice(verb)
v2 = random.choice(verb)
while v1 == v3 or v2 == v3:
v3 = choice(verb)
v3 = random.choice(verb)

# Pull three different adjectives
adj1 = choice(adjective)
adj2 = choice(adjective)
adj3 = choice(adjective)
adj1 = random.choice(adjective)
adj2 = random.choice(adjective)
adj3 = random.choice(adjective)
while adj1 == adj2:
adj2 = choice(adjective)
adj2 = random.choice(adjective)
while adj1 == adj3 or adj2 == adj3:
adj3 = choice(adjective)
adj3 = random.choice(adjective)

# Pull two different prepositions
prep1 = choice(preposition)
prep2 = choice(preposition)
prep1 = random.choice(preposition)
prep2 = random.choice(preposition)
while prep1 == prep2:
prep2 = choice(preposition)
prep2 = random.choice(preposition)

# Pull one adverb
adv1 = choice(adverb)
adv1 = random.choice(adverb)

if "aeiou".find(adj1[0]) != -1: # first letter is a vowel
if "aeiou".find(adj1[0]) != -1: # First letter is a vowel
article = "An"
else:
article = "A"

# add lines to poem
poem = f"{article} {adj1} {n1}\n\n"
poem = poem + f"{article} {adj1} {n1} {v1} {prep1} the {adj2} {n2}\n"
poem = poem + f"{adv1}, the {n1} {v2}\n"
poem = poem + f"the {n2} {v3} {prep2} a {adj3} {n3}"
# 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} a {adj3} {n3}"
)

return poem


print(make_poem())
poem = make_poem()
print(poem)