forked from winner9871/the-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsentence_maker.py
32 lines (28 loc) · 970 Bytes
/
sentence_maker.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
import random
# Vocabulary: words in 4 different parts of speech
ARTICLE = ("A", "THE")
NOUN = ("BOY", "GIRL", "BAT", "BALL")
VERB = ("HIT", "SAW", "LIKED")
PREPOSITION = ("WITH", "BY")
def sentence():
"""Builds and return sentence"""
return " ".join((nounPhase(), verbPhase()))
def verbPhase():
"""Builds and return verb phase"""
return " ".join((random.choice(VERB), nounPhase(), prepositionPhase()))
def prepositionPhase():
"""Builds and return preposition phase"""
return " ".join((random.choice(PREPOSITION), nounPhase()))
def nounPhase():
"""Builds and return noun phase"""
return " ".join((random.choice(ARTICLE), random.choice(NOUN)))
def main():
print("Anytime Enter 0 to exit")
while True:
sentenceCount = int(input("How many sentences you want :\t"))
if sentenceCount == 0:
break
for _ in range(sentenceCount):
print(sentence())
if __name__ == "__main__":
main()