[Edu-sig] a non-rhetorical question

Tom Hoffman tom.hoffman at gmail.com
Fri Jul 6 20:03:14 CEST 2007


On 7/6/07, Andy Judkis <ajudkis at verizon.net> wrote:
> Vern, Richard,
>
> Your comments were very helpful -- it's sometimes hard for me to see the
> question as a student would. They can imitate nicely, but asking them to
> analyze and synthesize (as this question does, at a very superficial level)
> seems to be asking a lot -- yet it's the essence of programming.
>
> Reading between the lines of Vern's message, I wonder how he would want
> students to answer the question.  What I was looking for was more or less
> what he considered the wise-guy answer:
>
> while True:
>     resp = raw_input("Who is hottest teacher?")
>     if resp == "Mr. Judkis":
>         print "Excellent choice!"
>         break
>     elif resp == "Mrs. McGrath":
>         print "Also a fine choice."
>         break
>     else:
>         print "Wrong, sorry. . ."

Here's the most elegant solution I could come up with:

teachers = {'Mr. Judkis':'Excellent Choice',
            'Mrs. McGrath':'Also a fine choice.'}
name = raw_input()
while name not in teachers.keys():
    print 'Wrong, sorry.'
    name = raw_input()
print teachers[name]

--Tom


More information about the Edu-sig mailing list