Write a program to build a sentence based on a random number of words entered by
ID: 3907789 • Letter: W
Question
Write a program to build a sentence based on a random number of words entered by the user.
The random number of words is to be generated by the program and should be an integer between five and twelve.
The program should request a separate input for each word entered (only enter one word at a time).
Print the complete sentence in uppercase with an exclamation point at the end.
Needs to have TRY and EXCEPT structure for numbers.
The code is exceptionally well organized and very easy to follow.
Variables/methods/functions are named appropriately. Variables/methods/functions are used efficiently and appropriately.
Use only python code, functions, methods and data structures that we have used in our course (this means not using/copying code you have encountered outside of assigned course materials). AND NAME THIS RANDOM .PY AND SEND THE OUTPUT
Explanation / Answer
from random import randint words = [] while True: word = input('Enter a word(quit to exit): ') if word == 'quit': break words.append(word) sentence = [] size = randint(5, 12) for i in range(size): sentence.append(words[randint(0, len(words)-1)]) print('Sentence is: ' + ' '.join(sentence) + '!')
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.