[Tutor] more problems, my final questions

Timothy M. Brauch tbrauch@mindless.com
Tue, 9 Jul 2002 22:44:34 -0400


One more time, hopefully this one will make it through (that is, if I send
it correctly).

----- Original Message -----
From: "Kyle Babich" <kb@kb5.org>
To: "tutor" <tutor@python.org>
Sent: Tuesday, July 09, 2002 10:08 PM
Subject: [Tutor] more problems, my final questions


> New problems has arisin.  I was wondering if there was way to replace:
> if begin in "Yy":
>         print "why is the sky blue?"
>
> With something like:
> if begin == "Y" "y":
>         print "why isn't the sky green or purple?"

You should be able to use either:
if begin in ['Y', 'y']:
        do something
        ...
or
if begin == 'Y' or begin == 'y':
        do something
        ...

I am not sure which one is preferred...
> (only unlike the code above I need something that works of course)
>
> I'm asking because I recently added:
> else begin in "CustomcustomCUSTOM":

In this case, I think it would be better to use the list:
if begin in ['Custom', 'custom', 'CUSTOM']:
        ...

> But I had also changed the Yy and Nn to be YyYesyesYES and NnNonoNO,
> however the o in No and the o and custom are conflicting and I'm trying
> to find a way to fix this.  Any ideas?

Although, a solution I just thought of that might make things even easier...
import string
...
begin = string.lower(begin)
if begin in ['y', 'yes']:
        ...

The third line converts begin to all lowercase (you could just as
arbitrarily use string.upper()) thus making the possible choices fewer.

Although, all of this is fly-by-the-seat-of-my-pants-untested code.  It
looks correct as I type it into my email...

> Also, my final questions regaurding this program:
> Could some one point me to an example or show me how to
> countdown/countup time.sleep?
> And the same goes for delaying/suspending and prematurly ending
> time.sleep.

Someone else will have to handle this.  I will admit I only listen to this
list with one ear, that is, only when I have free time, which seems to be
almost never.

> If anyone sees any problems-waiting-to-happen in my program (attached)
> please tell me.

Again, someone else...

> Thank you, this list has been so helpful.
> --
> Kyle

 - Tim