Goofy sentence generator

Started by Spartan, March 12, 2011, 11:05:19 PM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Spartan

The file size is only 2kb! I wrote it using python, so try it out (You need python, so if you dont have it you dont have to try it) Anyway, heres the file:
http://www.sendspace.com/file/h819ce
Scroll to the bottom where it says:
    Download link: Goofy.py


If you just want the code, here is that:

#This program is a goofy sentence generator.

import random
def make_sentence(part1, part2, part3, n=1):
   """return n random sentences"""
   #convert to lists here.
   p1 = part1.split('\n')
   p2 = part2.split('\n')
   p3 = part3.split('\n')
   #shuffle the lists here.
   random.shuffle(p1)
   random.shuffle(p2)
   random.shuffle(p3)
   #concatinate the sentences here.
   sentence = []
   for k in range(n):
       try:
           s = p1[k] + ' ' + p2[k] + ' ' + p3[k]
           s = s.capitalize() + '.'
           sentence.append(s)
       except IndexError:
           break
       return sentence

#break a typical sentence into 3 parts
#first part of a sentence (subject)
part1 = """\
a drunken sailor
a giggling goose
the yearning youth
the obese ostrich
this mean mouse
the skinny sister"""

#middle part of a sentence (middle)
part2 = """\
jumps over
flies over
runs across
openly ogles
twice tastes
vomits on"""

#ending part of a sentence (object)
part3 = """\
a rusty fence
the laughing cow
the weedcovered backyard
the timid trucker
the rancid old cheese
the jolly jelly"""

print '-'*60

sentence = make_sentence(part1, part2, part3, 3)
for item in sentence:
   print item
print '-'*60

#A typical result would be this:
# A drunken sailor flies over the laughing cow.

#Now we use raw_input to be able to stop and look at the result.
raw_input("Press <enter> when you're done.")


I will be making some actually "Helpful" programs soon, so wait for those. I will also get py2exe so you can just download the .exe and run that.
Feel free to add more sentences to the part's! To do this, just make a new line and write what you want.