Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
importing random lib import random function of genlistofwords def genlistofwordsnumofwords wordlist ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started