# goofy sentence generator import random def make_sentence(part1, part2, part3, n=1): """return n random sentences""" # convert to lists p1 = part1.split('\n') p2 = part2.split('\n') p3 = part3.split('\n') # shuffle the lists random.shuffle(p1) random.shuffle(p2) random.shuffle(p3) # concatinate the sentences 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 a tutting teacher a drugged mexican the yearning youth the obese ostrich this mean mouse the skinny sister""" # middle part of a sentence (action) part2 = """\ jumps over flies over dives under runs across openly ogles twice tastes vomits on""" # ending part of a sentence (object) part3 = """\ a rusty fence the stinky turd a hairy turtle 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 --> A drunken sailor flies over the laughing cow. The obese ostrich runs across the weedcovered backyard. This mean mouse openly ogles the jolly jelly. """
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question