1 {'article': ['the', 'a', 'one', 'few', 'any'], 2 'noun': ['boy', 'girl', 'food', 'cat', 'city', 'car'], 3...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1 {'article': ['the', 'a', 'one', 'few', 'any'], 2 'noun': ['boy', 'girl', 'food', 'cat', 'city', 'car'], 3 'verb': ['crossed', 'slipped', 'hit', 'walked', 'jumped'], 4 preposition': ['to', 'from', 'over', 'under', 'in', 'on'] Write a python function that uses random number generation to create sentences. The program should use a dictionary of lists with the keys article, noun, verb, and preposition as indicated below. The program should create a sentence by selecting a word at random from each array in the following order: article, noun, verb, preposition, article, and noun. As each word is picked, it should be concatenated to the previous words. The words should be separated by spaces. When the final sentence is output, it should start with a capital letter and end with a period. The function should generate n such sentences, where n is an input to the function. Then, the function should concatenate these sentences to produce a short story. The return value for this function is expected to be the story itself and the number of times a specific word target_word is used in the story. The dictionary for story generation, and the sample function call is provided below. 5} 6 7 #required function name and sample function call with the expected return vals out_story, word_ct = write_short story (3,"cat") # n=3, target_word = "cat" 8 1 {'article': ['the', 'a', 'one', 'few', 'any'], 2 'noun': ['boy', 'girl', 'food', 'cat', 'city', 'car'], 3 'verb': ['crossed', 'slipped', 'hit', 'walked', 'jumped'], 4 preposition': ['to', 'from', 'over', 'under', 'in', 'on'] Write a python function that uses random number generation to create sentences. The program should use a dictionary of lists with the keys article, noun, verb, and preposition as indicated below. The program should create a sentence by selecting a word at random from each array in the following order: article, noun, verb, preposition, article, and noun. As each word is picked, it should be concatenated to the previous words. The words should be separated by spaces. When the final sentence is output, it should start with a capital letter and end with a period. The function should generate n such sentences, where n is an input to the function. Then, the function should concatenate these sentences to produce a short story. The return value for this function is expected to be the story itself and the number of times a specific word target_word is used in the story. The dictionary for story generation, and the sample function call is provided below. 5} 6 7 #required function name and sample function call with the expected return vals out_story, word_ct = write_short story (3,"cat") # n=3, target_word = "cat" 8
Expert Answer:
Answer rating: 100% (QA)
The image you provided contains a prompt for writing a Python function called writeshortstory that t... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
A limerick is a humorous five-line verse in which the first and second lines rhyme with the fifth, and the third line rhymes with the fourth. Using techniques similar to those developed in Exercise...
-
Modify the sentence-generator program of Case Study sothat it inputs its vocabulary from a set of text files at startup.The filenames are nouns.txt, verbs. txt, articles.txt, andprepositions.txt. (...
-
On 1 January 2022, ABC Company issued 10,000 shares of common stock for $100,000. On 31 December 2022, the company declared and paid dividends of $10,000. Calculate the earnings per share and the...
-
Use the differential equation approach to find i0(t) for t > 0 in the circuit in Fig. P.22 and plot the response including the time interval just prior to opening the switch. 100 F - 12V
-
Set up appropriate systems of two linear equations in two unknowns and then solve the systems by determinants. All numbers are accurate to at least two significant digits. A moving walkway at an...
-
In a photoelectric-effect experiment, the maximum kinetic energy of electrons is \(2.8 \mathrm{eV}\). When the wavelength of the light is increased by \(50 \%\), the maximum energy decreases to \(1.1...
-
Middle Telecom provides communication services in Iowa, Nebraska, the Dakotas, and Montana. Middle purchased goodwill as part of the acquisition of Shipley Wireless Enterprises, which had the...
-
Dolittle Enterprises needs to spend $678,500 today to purchase a new machine. This machine will generate cash flows of $498,000 the first year and $354,000 the second year. After 2 years, the machine...
-
The figure shows reversed-phase retention data for three compounds. a. Identify whether compounds A, B, and C are weak acids or bases. For each compound, what is the pKap K a and the retention factor...
-
What are the types of word1, word2 and the return value for the following function definition? def total vowels(word1: """Return the number of vowels in words word1 and word2. word2: ) -> >>>...
-
Ansel is interested in environmental preservation. To that end, he has purchased vast amounts of land and kept it as undeveloped as possible. Recently, Ansel purchased 200 acres of land in Ohio at a...
-
Suppose the base case NPV of the project is $1,143,650.00 and the NPV is $1,362,406.00 when the sales volume is increased by 5,000 units. The sensitivity of the base case NPV to changes in the sales...
-
What are the fundamental differences between a monolithic kernel and a microkernel architecture, and how do these variances impact system performance and flexibility?
-
pwc.csod.com/lms/scorm/clientLMS/LMS3.aspx?rNum=1&aicc_sid=18846322... pwc.csod.com/lms/scorm/clientLMS/LMS3.aspx?rNum=1&aicc_sid=188463228p... pwc Prev O What is a key consideration to address...
-
An analysis is done about 20 selected hotels considering some characteristics. Customer overall satisfaction as well as characteristics such as comfort, amenities and in-house dining have been...
-
Dairy wastewater is treated in a series of CSTRS. The initial con- centration of complex organics in the wastewater is 1500 mg/L. The first order rate coefficient is 0.45 d-1. Detention time in each...
-
Independent random samples of sizes n1 = 30 and n2 = 50 are taken from two normal populations having the means 1 = 78 and 2 = 75 and the variances 21 = 150 and 22 = 200. Use the results of Exercise...
-
Write a method that computes the commission, using the scheme in Programming Exercise 5.39 . The header of the method is as follows:public static double?computeCommission(double?salesAmount)Write a...
-
Revise Programming Exercise 3.15 to add an additional $2,000 award if two digits from the user input are in the lottery number. Write a program that prompts the user to enter an integer for today?s...
-
Listing 6.8 implements the hex2Dec(String hexString) method, which converts a hex string into a decimal number. Implement the hex2Dec method to throw a NumberFormatException if the string is not a...
-
Required Do Exercise4.20 using the FIFO method of process costing. Explain any difference between the cost of work completed and transferred out and cost of closing work in progress in the Assembly...
-
Refer to the information in Exercise4.17. Suppose Telemark-Kjemi determines standard costs of NKr 1050 per (equivalent) tonne of transferred-in costs, NOK 390 per (equivalent) tonne of direct...
-
Required Do Exercise4.22 (1) using FIFO and four decimal places for unit costs. Explain any difference between the cost of work completed and transferred out and cost of closing work in progress in...
Study smarter with the SolutionInn App