Skip to content

Commit 45b6cc3

Browse files
committed
Pythonized the Random Sentences Script
1 parent c995fc0 commit 45b6cc3

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

random-sentences.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,27 @@
1515
verb = ["drove", "jumped", "ran", "walked", "skipped"]
1616
preposition = ["to", "from", "over", "under", "on"]
1717

18+
def random_int():
19+
return random.randint(0,4)
1820

1921
def random_sentence():
2022
"""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-
23+
return ("{} {} {} {} {} {}"
24+
.format(article[random_int()]
25+
,noun[random_int()]
26+
,verb[random_int()]
27+
,preposition[random_int()]
28+
, article[random_int()]
29+
,noun[random_int()])).capitalize()
30+
3431
# prints random sentences
32+
map(lambda x: print(random_sentence()), range(0, 20))
3533
for x in range(20):
3634
print(random_sentence())
3735

38-
print()
39-
print()
36+
print("\n")
4037

41-
# creates short story
42-
story = ""
43-
for x in range(20):
44-
story += random_sentence()
38+
story = (". ").join(list(map(lambda x: random_sentence(), range(0, 20))))
4539

46-
print(story)
40+
# prints random sentences story
41+
print("{}".format(story))

0 commit comments

Comments
 (0)