You have unnecessary variables, when you should use sequence and loop:
from random import choice
sentence = [
("I", "The stupid cheeser", "He", "She", "The pirate personperson"),
("killed", "ate", "vomited" "ate", ":)'ed"),
("the stupid cheeser2", "the moldy cheese", "the cow")
]
for values in sentence:
print choice(values),
print '.'
You are not only one who got the idea for this kind of program, actually: http://www.daniweb.com/software-development/python/threads/32007/projects-for-the-beginner#post159482
The style of code does leave also lot to be desired as it is very old program. Here what I came up by playing with vegaseats' code:
# goofy sentence generator
import random
def make_sentence(n, *parts):
"""return n random sentences"""
for _ in range(n):
yield ' '.join(random.choice(p) for p in parts).capitalize() + '.'
# break a typical sentence into 3 parts
# first part of a sentence (subject)
subject_ = """\
a drunken sailor
a giggling goose
the yearning youth
the obese ostrich
this mean mouse
the skinny sister""".splitlines()
# middle part of a sentence (action)
action_ = """\
jumps over
flies over
runs across
openly ogles
twice tastes
vomits on""".splitlines()
# ending part of a sentence (object)
object_ = """\
a rusty fence
the laughing cow
the weedcovered backyard
the timid trucker
the rancid old cheese
the jolly jelly""".splitlines()
print '-'*60
for item in make_sentence(3, subject_, action_, object_):
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.
"""
pyTony
pyMod
6,299 posts since Apr 2010
Reputation Points: 879
Solved Threads: 984
Skill Endorsements: 26