0

A series of different parts of sentences will be randomly put together to come up with new interesting sentences. using with Random, Integers, Print, Strings, Breaks, Functions, For, Range

2
Contributors
1
Reply
19
Views
2 Years
Discussion Span
Last Post by sneekula
1

Here is an example to get you started:

''' random_sentences101.py

# use this template to add more data
adjectives.append('')
subjects.append('')
verbs.append('')
objects.append('')

'''

import random

# create lists
adjectives = []
subjects = []
verbs = []
objects = []

# add data to the lists
adjectives.append('A small')
subjects.append(' boy')
verbs.append(' walked')
objects.append(' the fence')

adjectives.append('The big')
subjects.append(' trucker')
verbs.append(' climbed')
objects.append(' a tree')

adjectives.append('A tiny')
subjects.append(' frog')
verbs.append(' jumped over')
objects.append(' a log')

adjectives.append('The tardy')
subjects.append(' teacher')
verbs.append(' fell under')
objects.append(' two tables')


# construct n random sentences
n = 5
for k in range(n):
    sentence = random.choice(adjectives)
    sentence += random.choice(subjects)
    sentence += random.choice(verbs)
    sentence += random.choice(objects)

    print(sentence)

Edited by sneekula

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.