Skip to content

Commit 0c02fe6

Browse files
Merge pull request #248 from ephrimlawrence/master
Generates Random Sentences
2 parents 3bbb74a + 35d83d5 commit 0c02fe6

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

random-sentences.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Generates Random Sentences
2+
3+
Creates a sentence by selecting a word at randowm from each of the lists in
4+
the following order: 'article', 'nounce', 'verb', 'preposition',
5+
'article' and 'noun'.
6+
7+
The second part produce a short story consisting of several of
8+
these sentences -- Random Note Writer!!
9+
"""
10+
11+
import random
12+
13+
article = ["the", "a", "one", "some", "any"]
14+
noun = ["boy", "girl", "dog", "town", "car"]
15+
verb = ["drove", "jumped", "ran", "walked", "skipped"]
16+
preposition = ["to", "from", "over", "under", "on"]
17+
18+
19+
def random_sentence():
20+
"""Creates random and return sentences."""
21+
22+
sentence = ""
23+
sentence += article[random.randint(0, 4)] + " " + noun[random.randint(
24+
0, 4)] + " "
25+
sentence += verb[random.randint(0, 4)] + " " + preposition[random.randint(
26+
0, 4)] + " "
27+
sentence += article[random.randint(0, 4)] + " " + noun[random.randint(
28+
0, 4)] + ". "
29+
sentence = sentence[0].upper() + sentence[1:]
30+
31+
return sentence
32+
33+
34+
# prints random sentences
35+
for x in range(20):
36+
print(random_sentence())
37+
38+
print()
39+
print()
40+
41+
# creates short story
42+
story = ""
43+
for x in range(20):
44+
story += random_sentence()
45+
46+
print(story)

0 commit comments

Comments
 (0)