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
Edward is a composer and needs to listen to the most accurate music files to create his compositions. What audio file type shoul
svetoff [14.1K]

Answer:

MP3

Explanation:

From the question we are informed about Edward who is a composer and needs to listen to the most accurate music files to create his compositions. In this case, the audio file type he should use to record his music is MP3 format. MP3 format Is an audio format which is a coding use in digital audio with high quality that can be used to store songs on the computer without taking much space, but with good quality. MP3 offer to listen to his/her music clearly.

4 0
3 years ago
Use the writeln() method of the document object to display the current platform in a tag in the webpage. Hint: The platform prop
Allisa [31]

Using the knowledge in computational language in JAVA it is possible to write a code that the document object to display the current platform in a tag in the webpage

<h3>Writting the code in JAVA:</h3>

<em> <TABLE></em>

<em>      <ROWS> </em>

<em>      <TR> </em>

<em>      <TD>Shady Grove</TD></em>

<em>      <TD>Aeolian</TD> </em>

<em>      </TR> </em>

<em>      <TR></em>

<em>      <TD>Over the River, Charlie</TD></em>

<em>      <TD>Dorian</TD> </em>

<em>      </TR> </em>

<em>      </ROWS></em>

<em>      </TABLE></em>

<em>    </em>

<em />

See more about JAVA at brainly.com/question/12975450

#SPJ1

3 0
3 years ago
Jennifer is trying to install an anti-malware program on a computer that she believes might be infected. During the installation
sesenic [268]

Answer:

B. Install in Safe Mode.

Explanation:

Since Jennifer is using the administrator account, she should be able to install the program.

Hence, she should install the anti-malware software in Safe Mode.

In Computer science, Safe Mode is a mode in which the operating system loads only the bare minimum services, process and programs to boot or start up.

Hence, Safe Mode will ensure that when Jennifer is installing the anti-malware software, no other program or service is running which may interfere with her installation.

4 0
4 years ago
What is computer virus​
IRINA_888 [86]

Answer:

A type of malicious code or program written to alter the way a computer operates and is designed to spread from one computer to another.

Once a virus has successfully attached to a program, file, or document, the virus will lie dormant until circumstances cause the computer or device to execute its code. In order for a virus to infect your computer, you have to run the infected program, which in turn causes the virus code to be executed.

8 0
3 years ago
Read 2 more answers
Please describe in a few sentences
myrzilka [38]

Because a theorie is someones scientific quess on a matter so soon they get a understanding and change them. They are not discarded because they usually keep the same wording but not all so that it is correct then.

:)

4 0
3 years ago
Other questions:
  • I need help please <br> just plug in the words with their definitions.......
    10·2 answers
  • Information security is defined as practice of preventing unauthorized access, use, disclosure, disruption, modification, or ___
    6·1 answer
  • Slmething about device for defrosting windscreen?
    5·1 answer
  • gAssume that you are writing a program to merge two files named FallStudents and SpringStudents. Each file contains a list of st
    15·1 answer
  • What is the difference between a switch and a hub?
    8·1 answer
  • What is the most common representation of a distribution?
    14·1 answer
  • Trading stock or selling stock, selling real estate for profit, and selling other assets that gain value over time.
    13·1 answer
  • Dates of birth were entered into a computer program . The data was stored in the format DAY/MONTH/YEAR.The program rejected this
    12·1 answer
  • Why do we need to know the different Networking Devices?​
    10·1 answer
  • you're troubleshooting an ip addressing issue, and you issue a command to view the system's tcp/ip configuration. the command yo
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!