tom
By: a guest | May 27th, 2009 | Syntax:
Python | Size: 0.82 KB | Hits: 125 | Expires: Never
#!/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