 |  |

 |
 |  |  |
 | Welcome to CS1315. Click on the python to add comments.
|  |
 |  |  |
|
This page removed for FERPA compliance
|
        |
Midterm Exam 2 Review Spring 2003: Gendered random sentences
Comments? Concerns? Answers? Questions? Questions about Answers?
Back to Sp2003 Midterm Review 2
import random
def sentence(x):
nounsM = ["Mark", "Adam", "Larry", "Jose", "Matt", "Jim"]
nounsF = ["Angela", "Laura", "Meghan", "Mary"]
verbs = ["runs", "skips", "sings", "leaps", "jumps", "climbs", "argues", "giggles"]
phrases = ["in a tree", "over a log", "very loudly", "around the bREMOVEDh", "while reading the Technique"]
phrases = phrases + ["very badly", "while skipping","instead of grading", "while typing on the CoWeb."]
if x =="M":
print random.choice(nounsM), random.choice(verbs), random.choice(phrases)
if x=="F":
print random.choice(nounsF), random.choice(verbs), random.choice(phrases)
this code also works... it's jREMOVEDt a little different than yours above... i also added in some fun phrases, the random sentences can come out really funny...
import random
def sentence(x):
if x == "M":
nouns = ["Matt", "Drew", "Luke", "Bob"]
if x == "F":
nouns = ["Amy", "Ally", "REMOVED", "Courtney"]
verbs = ["screams", "plays", "dances", "kisses"]
phrases = ["like a mo-fo", "with yo mama", "in bed", "while hula hooping"]
print random.choice(nouns), random.choice(verbs), random.choice(phrases)
Student68
| REMOVED's a challenge: Add an object noun. "Amy kisses Matt while hula hooping." Mark Guzdial |
This works. I had to add a few prepositions to some of the verbs for them to make sense.
import random
def sentence(x):
if x == "M":
nouns= ["Matt", "Drew", "Luke", "Bob"]
objNouns= ["Amy", "Ally", "REMOVED", "Courtney"]
if x == "F":
nouns= ["Amy", "Ally", "REMOVED", "Courtney"]
objNouns= ["Matt", "Drew", "Luke", "Bob"]
verbs = ["screams at", "plays with", "dances with", "kisses"]
phrases = ["like a mo-fo", "with yo mama", "in bed", "while hula hooping"]
print random.choice(nouns), random.choice(verbs), random.choice(objNouns), random.choice(phrases)
Student116
Are you going to care how many nouns/objnouns/verbs/phrasrs we include in our program? Is there any minimum number? I ran mine with only three. Kelly Farrell
| Guess it depends on what I put in the problem statement... Mark Guzdial |
| You should know this for the final! Think about doing this with objects and/or functional programming. Mark Guzdial |
yeoo bum face
IF RAP WAS HASH I COULD BEAT TWISTA.
Links to this Page