answer.
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]
2 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]2 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
Look at the top 3 banking activities done via mobile banking vs. online banking. What characteristics do you notice for both?
muminat

Answer:  <em>The biggest difference between the two is their functionality. Internet Banking allows you to conduct online transactions through your PC or laptop and an internet connection. On the other hand, mobile banking can be done with or without internet. Many banks nowadays have their mobile apps for mobile banking.</em>

Disadvantages of Mobile Banking

<em>If the customer does not have a smartphone than the use of Mobile Banking becomes limited. A transaction like transfer of funds is only available on high-end phones. Regular use of Mobile Banking may lead to extra charges levied by the bank for providing the service.</em>

<em />

Explanation: <u><em>Was this helpful to you? if so please put me Brainlyest.</em></u>

4 0
2 years ago
Secure Wi-Fi networks and VPNs use _____ to secure data transferred over a network.
Aleksandr-060686 [28]

VPNs and Wifi networks use tunneling to send data privately over a network

4 0
2 years ago
python Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". Any value that is the same as the immediately preceding value i
Vika [28.1K]

int firstNumber,secondNumber = -1, duplicates = 0;

do {

cin >> firstNumber;

if ( secondNumber == -1) {

secondNumber = firstNumber;

}else {

if ( secondNumber == firstNumber )

duplicates++;

else

secondNumber = firstNumber;

}

} while(firstNumber > 0 );

cout << duplicates;

7 0
2 years ago
A large industrial machine is able to monitor environmental conditions and quickly shut down and sound an alarm when it detects
Tamiku [17]

The feature of technology that allows this to happen is d. reduced latency.

Latency is the amount of time it takes for data to be transmitted in a network. Reduced latency therefore refers to a situation where data is transmitted with speed.

Reduced latency allows:

  • better communication
  • reduced lag and,
  • better gaming

The machine in question is only able to quickly sound the alarm because it has low latency.

In conclusion, we can say that low latency enables the machine above to sound the alarm quickly which means that low latency is important to the safety of that environment.

<em>Find out more at brainly.com/question/9337524.</em>

Options for this question include:

a. improved bandwidth

b. connection density

c. effective range

d. reduced latency

6 0
2 years ago
Read 2 more answers
Which company has experienced censorship in China?
MariettaO [177]
Google experienced censorship in china. :) 
5 0
2 years ago
Read 2 more answers
Other questions:
  • Which of these is an on-site metric for social media marketing?
    13·1 answer
  • During college jesse spent four semesters studying abroad in other parts of the world how could jesses time abroad benefit his e
    5·2 answers
  • Write a method named lastFirst that accepts a string as its parameter representing a person's first and last name. The method sh
    13·1 answer
  • PHP is based on C rather than ______.
    5·1 answer
  • Justin signed a rental agreement for his new condo. How long is his lease? a p e x
    15·1 answer
  • Write the definition of a function power_to, which receives two parameters. The first is a float and the second is an integer. T
    5·1 answer
  • Doctors discovered a tumor in Amanda’s brain and used robotic surgery to remove it. Which best describes the role a worker in th
    15·2 answers
  • You discover many errors in a database table. What has been lost?
    15·2 answers
  • As a security engineer, compare and contrast the pros and cons of deploying hetero vs homogenous networks. Which costs more? Whi
    6·1 answer
  • Factoring of integers. Write a python program that asks the user for an integer and then prints out all its factors. For example
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!