Modify the sentence-generator program so that it inputs its vocabulary from a set of text files at startup. The filenames are no
uns.txt, verbs. txt, articles.txt, and prepositions.txt.
(Hint: 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.)
The code below
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 returns a noun phrase."""
return random.choice(articles) + " " + random.choice(nouns)
def verbPhrase():
"""Builds and returns a verb phrase."""
return random.choice(verbs) + " " + nounPhrase() + " " + \
prepositionalPhrase()
def prepositionalPhrase():
"""Builds and returns a prepositional phrase."""
return random.choice(prepositions) + " " + nounPhrase()
def main():
"""Allows the user to input the number of sentences
to generate."""
number = int(input("Enter the number of sentences: "))
for count in range(number):
print(sentence())
# The entry point for program execution
if __name__ == "__main__":
main()
1 answer:
You might be interested in
Answer:
С.) The force acting on the pole exceeded its yield strength.
Explanation:
Answer:
None of these
Explanation:
There are different types of amplifiers, and each has different characteristics.
- Voltage amplifier needs high input and low output resistance.
- Current amplifier needs Low Input and High Output resistance.
- Trans-conductance amplifier Low Input and High Output resistance.
- Trans-Resistance amplifier requires High Input and Low output resistance.
Therefore, the correct answer is "None of these "
Answer:
<u>construction workers</u>
Explanation:
A construction worker is usually someone with the technical skills and abilities needed to manually construct physical infrastructures.
Since a walkway is an infrastructure, hiring skilled construction workers should perform the project of building the series of walkways within the large garden apartment.
Answer:
c,d,e
Explanation:
rude, so you can keep safe and so you can really learn