Question

INTRODUCTORY PYTHON QUESTION For my Intro to Python class, I need a very simple program that...

INTRODUCTORY PYTHON QUESTION

For my Intro to Python class,

I need a very simple program that generates random sentences using a dictionary / list and the random.choice function. The program must ask user how many sentences they want generated.

The dictionary can look like this, just not sure where to go from here:

words = [["The", "A"],
["young", "energetic", "happy", "small", "cute"],
["boy", "dog", "cat", "girl", "student", "child"],
["ate the homework.", "played with the ball.", "jumped on the desk.", "ate their dinner.", "hit the ball."]

example console output:

Enter the number of sentences: 2

The boy ate the homework.

A girl played with the ball.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import random

words = [["The", "A"],
         ["young", "energetic", "happy", "small", "cute"],
         ["boy", "dog", "cat", "girl", "student", "child"],
         ["ate the homework.", "played with the ball.", "jumped on the desk.", "ate their dinner.", "hit the ball."]]

n = int(input("Enter the number of sentences: "))
for i in range(n):
    sentence = ''
    for lst in words:
        sentence += random.choice(lst) + ' '
    print(sentence.strip())

Add a comment
Know the answer?
Add Answer to:
INTRODUCTORY PYTHON QUESTION For my Intro to Python class, I need a very simple program that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python 3 Modify the sentence-generator program of Case Study so that it inputs its vocabulary from...

    Python 3 Modify the sentence-generator program of Case Study so that it inputs its vocabulary from a set of text files at startup. The filenames are nouns.txt, verbs. txt, articles.txt, and prepositions.txt. (HINT: Define a single new function, getWords. This function should expect a filename as an argument. The function should open an input file with this name, define a temporary list, read words from the file, and add them to the list. The function should then convert the list...

  • I need help with my python class. thanks! Question 12 Code Example 4-4 main program: import...

    I need help with my python class. thanks! Question 12 Code Example 4-4 main program: import arithmetic as a def multiply(num1, num2):     product = num1 * num2     result = a.add(product, product)     return result     def main():     num1 = 4     num2 = 3     answer = multiply(num1, num2)     print("The answer is", answer) if __name__ == "__main__":     main() arithmetic module: def add(x, y):     z = x + y     return z Refer to Code...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT