[Tutor] Engarde program was: i++
Alan Gauld
alan.gauld at btinternet.com
Thu Jun 7 18:21:48 CEST 2007
> What if the user enters "maybe".
Sorry, I said the except block i meant the else block of
the original posters code.
In both his case and yours the message gets printed.
But as Danny pointed out you need the try/except in
your case because you are indexing a potentially
empty string. The OP didn't have that limitation to
deal with.
Alan G.
>
>
> -----Original Message-----
> From: tutor-bounces+david.heiser=intelliden.com at python.org
> [mailto:tutor-bounces+david.heiser=intelliden.com at python.org] On
> Behalf
> Of Alan Gauld
> Sent: Thursday, June 07, 2007 1:45 AM
> To: tutor at python.org
> Subject: Re: [Tutor] Engarde program was: i++
>
>
>
> "David Heiser" <David.Heiser at intelliden.com> wrote
>>
>> def is_yes(question):
>> while True:
>> try:
>> s = raw_input(question).lower()[0]
>> if s == 'y':
>> return True
>> elif s == 'n':
>> return False
>> except:
>> pass ## This traps the condition where a user just
>> presses enter
>> print '\nplease select y, n, yes, or no\n'
>
> What value do you think the pass adds over just having
> the print statement inside the except block? So far as I can
> tell they will both do exactly the same so the pass is
> not needed. Or am I missing something here?
>
> Alan G.
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list