1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mila [183]
4 years ago
15

Modify the sentence-generator program of Case Study so that it inputs its vocabulary from a set of text files at startup. The fi

lenames are nouns.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 ini- tialize each of the four variables for the vocabulary.)Case Study: Generating Sentences code:import randomarticles = ("A", "THE")nouns = ("BOY", "GIRL", "BAT", "BALL")verbs = ("HIT", "SAW", "LIKED")prepositions = ("WITH", "BY")def sentence():return nounPhrase() + " " + verbPhrase()def nounPhrase():return random.choice(articles) + " " + random.choice(nouns)def verbPhrase():return random.choice(verbs) + " " + nounPhrase() + " " + \prepositionalPhrase()def prepositionalPhrase():return random.choice(prepositions) + " " + nounPhrase()def main():number = int(input("Enter the number of sentences: "))for count in range(number):print(sentence())if __name__ == "__main__":main()

Computers and Technology
1 answer:
Snezhnost [94]4 years ago
6 0

Answer:

Go to explaination for the program code.

Explanation:

Before running the program you need to have these files created like below in your unix box.

Unix Terminal> cat nouns.txt

BOY

GIRL

BAT

BALL

Unix Terminal> cat articles.txt

A

THE

Unix Terminal> cat verbs.txt

HIT

SAW

LIKED

Unix Terminal> cat prepositions.txt

WITH

BY

Unix Terminal>

Code:

#!/usr/local/bin/python3

import random

def getWords(filename):

fp = open(filename)

temp_list = list()

for each_line in fp:

each_line = each_line.strip()

temp_list.append(each_line)

words = tuple(temp_list)

fp.close()

return words

articles = getWords('articles.txt')

nouns = getWords('nouns.txt')

verbs = getWords('verbs.txt')

prepositions = getWords('prepositions.txt')

def sentence():

return nounPhrase() + " " + verbPhrase()

def nounPhrase():

return random.choice(articles) + " " + random.choice(nouns)

def verbPhrase():

return random.choice(verbs) + " " + nounPhrase() + " " + prepositionalPhrase()

def prepositionalPhrase():

return random.choice(prepositions) + " " + nounPhrase()

def main():

number = int(input('Enter number of sentences: '))

for count in range(number):

print(sentence())

if __name__=='__main__':

main()

kindly check attachment for code output and onscreen code.

You might be interested in
You want to change your cell phone plan and call the company to discuss options
Vikki [24]
And? What’s the point? The question?
3 0
3 years ago
Which phrase refers to the collection of geospatial data through the use of satellite images/pictures?
love history [14]

Answer:

The appropriate answer will be "Using remote sensing".

Explanation:

<u>Such basic applications of Earth's remote sensing images usually involve: </u>

  • Heavily forested fires could be viewed out of space, enabling the wanderers to have a much wider area than those of the field.
  • Trying to track particles to accurately forecast the weather either watch volcanic eruptions, including helping out for outbreaks of dust.

So that the above is the correct solution.

5 0
3 years ago
What is control structure write it's types​ .
MAXImum [283]

Answer

<u>Defination</u><u>-</u><u>:</u>

A control statement is a statement and a statement whose execution its control.

<u>Types-:</u>

  • Selection Statement
  • Iteration Statement
  • Unconditional branching Statement
4 0
3 years ago
What do you think is the most important factor affecting the collection of digital data and what impact do you think that this f
borishaifa [10]

<u>Answer:</u>

<u>Privacy concerns.</u>

<u>Explanation:</u>

Privacy concerns have played an important role in how we collect digital data. For example, privacy activists believe that an individual has the right to know how his or her information is being used and that such an individual also has the right to withhold such information.

Such issues have affected the ability of law enforcement agencies to investigate criminal activities. For example, an individual who is accused of a crime may claim a <em>right to withhold his personal information, such as his mobile device, and thus he refuses to give out such information.</em>

4 0
3 years ago
Refer to the exhibit. pc1 issues an arp request because it needs to send a packet to pc3. in this scenario, what will happen nex
Sauron [17]
RT1 will send an ARP answer with its own particular Fa0/0 MAC address.When a system gadget needs to speak with a gadget on another system, it communicates an ARP ask for requesting the default portal MAC address. The default portal (RT1) unicasts an ARP answer with the Fa0/0 MAC address.
5 0
4 years ago
Other questions:
  • Can someone can help me am dont know how much RAM do i need. I use my pc for work and to watch yt vid. Thanks​
    10·1 answer
  • An “AI” (artificial intelligence) could be used in:
    10·1 answer
  • If you wanna buy a Monitor, please explain why you wanna buy it! PLEASE HELP ME!!!!!!!!!!!!!!!!!!!!!!!!!
    9·1 answer
  • When the speaker compares dream memories to fall leaves that are hard to catch,what feeling does the simile suggest?
    14·2 answers
  • Which description best describes how mass spectroscopy is useful in the field of forensic toxicology
    6·1 answer
  • Passing structured query language commands to a web application and getting the website to execute it is called SQL script:_____
    12·1 answer
  • Return 1 if ptr points to an element within the specified intArray, 0 otherwise.
    7·1 answer
  • 58:30
    8·1 answer
  •  In which part of a professional email should you try to be brief, but highly descriptive? 
    10·1 answer
  • How are computers connected to one another?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!