[Tutor] 'if a==b or a==c or a==d' alternative (was: pausing and layout)

Don Arnold Don Arnold" <darnold02@sprynet.com
Sun Jan 5 01:04:01 2003


---- Original Message -----
From: "Michael Janssen" <Janssen@rz.uni-frankfurt.de>
To: "mike O" <skitzomonkey@hotmail.com>
Cc: <tutor@python.org>
Sent: Saturday, January 04, 2003 11:47 AM
Subject: Re: [Tutor] pausing and layout


On Sat, 4 Jan 2003, mike O wrote:

>> I guess I have three questions, the first being: Is there a python
command
>> to pause until the user does something?
>Hello Mike

>In addition to Gonçalo's reply I want to say that raw_input() is typically
>used in a while loop:

>from types import IntType
         ...

>    while 1:
>        p = raw_input("Choose a Number or [Q]uit: ")
>        if p == "Q" or p == "q" or p == "":
>            # User requests the end of the game
>            sys.exit()
<snip>

I've come to the conclusion that I like the seemingly SQL'ish alternative to
the 'if' statement above:

if p in ('Q','q',''):
    sys.exit()

It scans easily (to my eyes), and gives me fewer chances to typo.

Don