Final answer:
Modify the sentence-generator program by creating a function called 'getWords' that takes a filename, reads its contents, and returns a tuple. Use this function to initialize vocabulary variables from text files, thereby making the program dynamically use the words provided in the files.
Step-by-step explanation:
To modify the sentence-generator program so that it inputs its vocabulary from text files, we can create a new function called getWords to handle the file reading. The getWords function will take the filename as an argument, after which it reads the file line by line, adds each line to a list and then converts that list to a tuple which it returns. The returned tuple will be used to initialize the vocabulary variables in the program.
Updated Code Snippet:
import random
def getWords(filename):
with open(filename, 'r') as file:
words = [word.strip() for word in file.readlines()]
return tuple(words)
articles = getWords('articles.txt')
nouns = getWords('nouns.txt')
verbs = getWords('verbs.txt')
prepositions = getWords('prepositions.txt')
# ... rest of the program ...
With this modification, the vocabulary of the sentence-generator will be based on the words provided in the corresponding text files, making it dynamic and customizable.