Random Sentences

s
e
c
n
e
t
n
m Se
o
d
n
Ra
Step
g
n
i
m
m
a
gr
o
r
P
o
t
by Step
Just talk about grammar and
sentence construction
!   Come up with some simple sentence forms.
!   print("The cat bit the cheese")
Make a sentence template
!   noun1="cat"
!   verb="bit"
!   noun2="cheese"
!   print("The", noun1, verb, "a", noun2)
Ask the user for the noun/
verb
!   noun1="cat"
!   verb=input("What did the first noun do to the
second noun? ")
!   noun2="cheese"
!   print("The", noun1, verb, "a", noun2)
Choose something from a list
of words
!   import random
!   noun1=random.choice(["cat","dog","man","frog","monster"])
!   noun2=random.choice(["pencil","apple","house","TV","toy"])
!   verb=random.choice(["ate","watches","spat","licked","sat
on"])
!   print("The", noun1, verb, "a", noun2) Choose words from cunningly
prepared dictionary files!
!   import random
!   noun1= random.choice(open("noun1.txt").readlines())
!   noun2= random.choice(open("noun2.txt").readlines())
!   verb= random.choice(open("verb.txt").readlines())
!   print("The", noun1, verb, "a", noun2)
More Stuff…
!   Make the template more involved with adjectives and adverbs
!   For advanced students, try making the articles part of the template.
Also see if they can get ‘a/an’ to agree with the spelling of the noun!
!   noun1= random.choice(open("noun1.txt").readlines())
!   if noun1[0:1] in "aeiou":
!  
article1=random.choice(["The","An"])
!   else:
!  
article1=random.choice(["The","A"])
!   Try and get the dictionaries off the web. Import urllib and use
urllib.open() instead of open()