Question: Use the random module to create a program that creates nonsense poetry. The poem must satisfy the follow requirements: (a) It contains exactly 3

Use the random module to create a program that creates nonsense poetry.The poem must satisfy the follow requirements: (a) It contains exactly 3  

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.

Step by Step Solution

3.34 Rating (151 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

importing random lib import random function of genlistofwords def genlistofwordsnumofwords wordlist ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!