The Easiest Way to Save and Share Code Snippets on the web

awful_poetry.py

python

posted: May, 31st 2009 | jump to bottom

#!/usr/bin/env python3
 
import sys
import random
 
articles = ["the", "his", "her", "somebody's", "nobody's", "a"]
subjects = ["cat", "hat", "flamingo", "bear", "turd", "belt"]
verbs = ["cried", "laughed", "ran", "melted", "jumped", "ate"]
adverbs = ["loudly", "sadly", "quietly", "mightily", "haughtily", "badly"]
structures = [(articles, subjects, verbs, adverbs), (articles, subjects, verbs)]
 
lines = 5
 
while True:
    try:
        line = input("Enter a number between 1 and 10: ")
        number = int(line)
 
        if 1 <= number <= 10:
            lines = number
 
        break
    except ValueError as err:
        print(err)
        continue
 
while lines:
    poem = ""
    for content in structures[random.randint(0,1)]:
        poem += random.choice(content) + " "
    print(poem)
    lines-=1
 
138 views