Home / Expert Answers / Computer Science / given-the-following-scriptimport-randomarticles-34-a-34-34-the-34-nouns-34-boy-34-34-girl-34-34-bat--pa764

(Solved): Given the following scriptimport randomarticles = ("A", "THE")nouns = ("BOY", "GIRL", "BAT", "BALL") ...



Given the following script
import random
articles = ("A", "THE")
nouns = ("BOY", "GIRL", "BAT", "BALL")
verbs =("HIT", "SAW", "LIKED")
prepositions =("WITH", "BY")
def sentence():
"""Builds and returns a sentence"""
return nounPhrase() + ""+ verbPhrase()

def nounPhrase():
"""Builds and return a noun phrase"""
return random.choice(articles) + ""+ random.choice(nouns)

def verbPhrase():
"""Builds and return a verb phrase"""
return random.choice(verbs) + "" + nounPhrase + prepositionalPhrase()

defprepositionPhrase():
"""Builds and returns a prepositional phrase"""
Return random.choice(prepositions) + "" + nounPhrase()

def main():
"""Let user input number of sentences to be generated"""
number = int(input("Enter the number of sentences: "))
for count in range(number):
print(sentence())
main() #call to main

Modify the script so you can add adjectives to write random sentences such as THE BOY HIT THE RED BALL., or the BALL HIT THE RED BOY. Add additional words of your own. Finally ask the user how many sentences are to generated.
Using python



We have an Answer from Expert

View Expert Answer

Expert Answer



Here's the modified script that allows for adjectives and takes user input for the number of sentences to generate:
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe