November 10, 2024, 09:18:21 pm

Author Topic: Goofy sentence generator  (Read 3362 times)

0 Members and 1 Guest are viewing this topic.

Spartan

  • Follow my Twitter!
  • Champion Member
  • ***
  • Posts: 1792
  • I'm back
    • View Profile
Goofy sentence generator
« on: March 12, 2011, 11:05:19 pm »
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:

Code: [Select]
#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.
« Last Edit: March 12, 2011, 11:23:15 pm by spartan_rain »