I need to generate sentences using python. I have the words I need intact but can't figure out how to make it so only correct sentences come out after I run it.
Here's my code
import random
def S():
print DP(), VP()
def DP():
detPhrase = D() + ' ' + N()
return detPhrase
def VP():
randInt = random.randint(0,1)
if randInt == 0:
return V()
else:
return V() + ' ' + DP()
def N():
nouns = ['cat', 'dog', 'Bella']
randInt = random.randint(0,len(nouns)-1)
return nouns[randInt]
def D():
articles = ['the', 'to']
randInt = random.randint(0,len(articles)-1)
return articles[randInt]
def V():
verbs = ['ran','kissed','gave']
randInt = random.randint(0,len(verbs)-1)
return verbs[randInt]
for num in range(30):
S()