 |  |

 |
 |  |  |
 | Welcome to CS1315. Click on the python to add comments.
|  |
 |  |  |
|
This page removed for FERPA compliance
|
        |
Midterm Exam 2 Review Fall 2003: Gendered random sentences
Answers? Comments? Questions on Answers? Questions on Comments?
(Back to Fall2003 Midterm Review 2)
this is just like the lecture slide, you just have to add male or female
| And a little REMOVED than that. Like an IF. Or two. Mark Guzdial |
This doesn't work because I don't know how to input a string. But I think that's the only problem.
import random
def sentence(input):
mNouns = ["Mark", "Adam", "Larry", "Jose", "Matt", "Jim"]
fNouns = ["Angela"]
verbs = ["runs", "skips", "sings", "leaps", "jumps", "climbs", "argues", "giggles"]
phrases = ["in a tree", "over a log", "very loudly", "around the bush", "while reading the Technique"]
phrases = phrases + ["very badly", "while skipping","instead of grading", "while typing on the CoWeb."]
if input=="m":
print random.choice(mNouns), random.choice(verbs), random.choice(phrases)
if input=="f":
print random.choice(fNouns), random.choice(verbs), random.choice(phrases)
Now it works - stupid colons, I always forget.
| If we could only have smarter colons... |
Seriously, why do you have to have them? It seems redundant. The indentation should be enough of an indicator.
| The colons tell you that you need indentation next! It's a clue to the programmer that after IF or FOR or WHILE or DEF, you need a block, so it's time to indent. Mark Guzdial |
def sentence(input):
verbs = ["runs", "skips", "sings", "leaps", "jumps", "climbs", "argues", "giggles"]
phrases = ["in a tree", "over a log", "very loudly", "around the bush", "while reading the Technique"]
phrases = phrases + ["very badly", "while skipping","instead of grading", "while typing on the CoWeb."]
if input =="M":
nouns = ["Matt", "Bill", "Michael", "REMOVED"]
if input =="F":
nouns = ["Karen", "Danielle", "Jenni"]
print random.choice(nouns), random.choice(verbs), random.choice(phrases)
Why wont this work?
Are you asking why it doesn't work, or why it wouldn't work? Because I think it would - make sure you're inputting a string, like so: sentence("M") and not just the letter M. And make sure you import random.
Mr. Guzdial, I really liked this question ;)
Link to this Page