Question: Modify the sentence - generator program of Case Study 5 . 3 : METIS book: 9 7 8 1 3 3 7 6 7 1
Modify the sentencegenerator program of Case Study :
METIS book: page
so that it inputs its vocabulary from a set of text files at startup. The filenames are nouns.txt verbs. txt articles.txt and prepositions.txtHint: Define a single new function, getWords. This function should expect a filename as an argument. The function should open an input file with this name, define a temporary list, read words from the file, and add them to the list. The function should then convert the list to a
tuple and return this tuple. Call the function with an actual filename to initialize each of the four variables for the vocabulary.
Here's the python source code generator.py:
Program: generator.py
Author: Ken
Generates and displays sentences using a simple grammar
and vocabulary. Words are chosen at random.
import random
articles A "THE"
nouns BOY "GIRL", "BAT", "BALL"
verbs HIT "SAW", "LIKED"
prepositions WITHBY
def sentence:
Builds and returns a sentence."""
return nounPhrase verbPhrase
def nounPhrase:
Builds and returns a noun phrase."""
return random.choicearticles random.choicenouns
def verbPhrase:
Builds and returns a verb phrase."""
return random.choiceverbs nounPhrase
prepositionalPhrase
def prepositionalPhrase:
Builds and returns a prepositional phrase."""
return random.choiceprepositions nounPhrase
def main:
Allows the user to input the number of sentences
to generate."""
number intinputEnter the number of sentences:
for count in rangenumber:
printsentence
# The entry point for program execution
if namemain:
main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
