[Edu-sig] a non-rhetorical question
Vern Ceder
vceder at canterburyschool.org
Fri Jul 6 20:22:30 CEST 2007
Tom,
Yeah, if they've got dictionaries, then your way is both elegant and
"Pythonic" ;-)
Cheers,
Vern
Tom Hoffman wrote:
> 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
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
--
This time for sure!
-Bullwinkle J. Moose
-----------------------------
Vern Ceder, Director of Technology
Canterbury School, 3210 Smith Road, Ft Wayne, IN 46804
vceder at canterburyschool.org; 260-436-0746; FAX: 260-436-5137
More information about the Edu-sig
mailing list