Use the random module to create a program that creates nonsense poetry. The poem must satisfy...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Use the random module to create a program that creates nonsense poetry. The poem must satisfy the follow requirements: (a) It contains exactly 3 lines. (b) The first line contains 4 words chosen randomly (without repeats) from a specified list of 20 words. (c) The second line contains 6 words in total. The final word must be chosen randomly from the first line; the remaining words should be chosen randomly (without repeats) from the list of 20 words. (d) The third line contains 4 words in total. The first word must be chosen randomly from the second line; the remaining words should be chosen randomly (without repeats) from the list of 20 words. (e) The probability that a word is capitalised is given by 1/(0.75*number of letters). Thus a word with four letters is capitalised with prob- ability of 33%. (f) The words should be separated by a single space. (g) Add a comma at end of line 1, an exclamation mark at the end of line 2, and a period at the end of line 3. The punctuation marks should follow the words without an additional space. Requirements: • Use a function gen list.of.words that chooses a specified num- ber of randomly selected words and capitalises them with speci- fied probability. It should take two arguments only. • Use a function output line to output the words on each line. • Use an explicit main. The main program definition should contain no more than 5 lines. Use the following list of words bunny blue cub there is are breakfast the at name eat end of fantastic dinner time go for I you Hints: (a) Try to work with lists. (b) The probability of selecting a mumber in an interval is related to the width of the interval. random.random () generates random numbers in the interval (0, 1). Sample output is shown below: BREAKFAST bunny THERE OF, FOR the name YOU dinner there! you bunny name GO. is bunny at name, fantastic name IS time cub IS! CUB breakfast cub TIME. Use the random module to create a program that creates nonsense poetry. The poem must satisfy the follow requirements: (a) It contains exactly 3 lines. (b) The first line contains 4 words chosen randomly (without repeats) from a specified list of 20 words. (c) The second line contains 6 words in total. The final word must be chosen randomly from the first line; the remaining words should be chosen randomly (without repeats) from the list of 20 words. (d) The third line contains 4 words in total. The first word must be chosen randomly from the second line; the remaining words should be chosen randomly (without repeats) from the list of 20 words. (e) The probability that a word is capitalised is given by 1/(0.75*number of letters). Thus a word with four letters is capitalised with prob- ability of 33%. (f) The words should be separated by a single space. (g) Add a comma at end of line 1, an exclamation mark at the end of line 2, and a period at the end of line 3. The punctuation marks should follow the words without an additional space. Requirements: • Use a function gen list.of.words that chooses a specified num- ber of randomly selected words and capitalises them with speci- fied probability. It should take two arguments only. • Use a function output line to output the words on each line. • Use an explicit main. The main program definition should contain no more than 5 lines. Use the following list of words bunny blue cub there is are breakfast the at name eat end of fantastic dinner time go for I you Hints: (a) Try to work with lists. (b) The probability of selecting a mumber in an interval is related to the width of the interval. random.random () generates random numbers in the interval (0, 1). Sample output is shown below: BREAKFAST bunny THERE OF, FOR the name YOU dinner there! you bunny name GO. is bunny at name, fantastic name IS time cub IS! CUB breakfast cub TIME.
Expert Answer:
Answer rating: 100% (QA)
importing random lib import random function of genlistofwords def genlistofwordsnumofwords wordlist ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
The package inheritance hierarchy (below) to create a program that displays the address information and calculates the shipping costs for several packages. The program should contain a vector of...
-
In this exercise, you will create a program that allows the user to enter an employees gross pay amount as well as his or her filing status and number of withholding allowances. The program should...
-
In this exercise, you will create a program that displays the number of daily calories needed to maintain your current weight. The number of calories is based on your gender, activity level, and...
-
Define price and name the various types of prices described in this chapter.
-
1. Which organizational structure described in the chapter does Volkswagens customer oriented structure most closely resemble? 2. How might such a structure help or hinder entry into new markets? 3....
-
Lets filter the data by customer. Make a copy of the data worksheet. Name the new worksheet tab Filter. Create a filter for customer number 3013. Copy the resulting data into row 235 (so you can...
-
Determine the magnitude of the horizontal component of the anchoring force required to hold in place the sluice gate shown in Fig. 5.59. Compare this result with the size of the horizontal component...
-
M. M. Sprout, a catalog mail order retailer, has one customer service representative (CSR) to take orders at an 800 telephone number. If the CSR is busy, the next caller is put on hold. For...
-
Observe one social studies and one ELA lesson in your mentor teacher's classroom. If social studies is not being taught, collaborate with your mentor to locate another classroom to observe. During...
-
Background: A new ownership group has recently purchased ABC Liquors. You have been hired by the new management team to analyze their sales data for the past year and provide them with insights about...
-
An economy is characterized by the following equation-Consumption C= 60+0.9Yd Investment I = 10 Government expenditure G = 10Tax T=0 Exports X = 20 Imports M = 10 +0.05 Y Find equilibrium income and...
-
What implication might these behavioral biases have for the CAPM?
-
How does the volatility of an equally weighted portfolio change as more stocks are added to it?
-
Why might firms prefer to fund investments using retained earnings or debt rather than issuing equity?
-
What must be true about the behavior of small, uninformed investors for them to have an impact on market prices?
-
In what ways might managers benefit by overspending on acquisitions?
-
Watch the following podcast given below and give your views about it https://www.youtube.com/watch?v=CYVEwUjr4t8
-
Repeat Exercise 16.6 using the t-test of the coefficient of correlation. Is this result identical to the one you produced in Exercise 16.6?
-
The following pseudocode describes how to extract the dollars and cents from a price given as a floating-point value. For example, a price 2.95 yields values 2 and 95 for the dollars and cents....
-
Implement a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has a description (for example, see the dentist) and a date. Write a method occursOn(int year, int month,...
-
Make up a Java code example that shows the dangling else problem using the following statement: A student with a GPA of at least 1.5, but less than 2, is on probation. With less than 1.5, the student...
-
State Newton's second law as you would apply it to a control mass.
-
Explain the significance of \(g_{c}\) in Newton's second law. What are the magnitude and units of \(g_{c}\) in the English Engineering system? In the SI system?
-
Define a 1-pound force in terms of the acceleration it will give to a 1-pound mass. Give a similar definition for a newton in the SI system.
Study smarter with the SolutionInn App