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.
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())

INTRODUCTORY PYTHON QUESTION For my Intro to Python class, I need a very simple program that...
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 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...