Posted by tom on Thu 28 May 02:30
report abuse | View followups from tom | download | new post
- #!/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
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.