-
Notifications
You must be signed in to change notification settings - Fork 0
/
random words.py
58 lines (52 loc) · 1.18 KB
/
random words.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
the yearning youth
the obese ostrich
this mean mouse
the skinny sister"""
# middle part of a sentence (action)
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)
input('<press enter>')