Share Pastebin
Guest
Public paste!

tom

By: a guest | May 27th, 2009 | Syntax: Python | Size: 0.82 KB | Hits: 125 | Expires: Never
Copy text to clipboard
  1. #!/usr/bin/env python3
  2.  
  3. import sys
  4. import random
  5.  
  6. articles = ["the", "his", "her", "somebody's", "nobody's", "a"]
  7. subjects = ["cat", "hat", "flamingo", "bear", "turd", "belt"]
  8. verbs = ["cried", "laughed", "ran", "melted", "jumped", "ate"]
  9. adverbs = ["loudly", "sadly", "quietly", "mightily", "haughtily", "badly"]
  10. structures = [(articles, subjects, verbs, adverbs), (articles, subjects, verbs)]
  11.  
  12. lines = 5
  13.  
  14. while True:
  15.     try:
  16.         line = input("Enter a number between 1 and 10: ")
  17.         number = int(line)
  18.            
  19.         if 1 <= number <= 10:
  20.             lines = number
  21.  
  22.         break
  23.     except ValueError as err:
  24.         print(err)
  25.         continue
  26.  
  27. while lines:
  28.     poem = ""
  29.     for content in structures[random.randint(0,1)]:
  30.         poem += random.choice(content) + " "
  31.     print(poem)
  32.     lines-=1