2007-01-25 11:26:09
[EMAIL PROTECTED] wrote in message
<[EMAIL PROTECTED]>
> Hmm, my while loop with "or" doesn't seem to work as I want it to...
> How do I tell the while loop to only accept "Y" or "y" or "N" or
"n"
> input from the str(raw_input)?
>
> Thank's in advance!
>
> Snippet of code:
[EMAIL PROTECTED] a écrit :
>
> On Jan 25, 11:26 am, [EMAIL PROTECTED] wrote:
(snip)
>> #Runs the buildfinder function
>> usrinp = buildfinder()
>>
>> def buildwhiler():
>>
>> while usrinp != "y" or "Y" or "N" or "n": PROBLEM
>> print "Enter Y or N!"
>> usr = str(raw_in
On Jan 25, 11:26 am, [EMAIL PROTECTED] wrote:
> Hmm, my while loop with "or" doesn't seem to work as I want it to...
> How do I tell the while loop to only accept "Y" or "y" or "N" or "n"
> input from the str(raw_input)?
>
> Thank's in advance!
>
> Snippet of code:
>
> import os
>
> def buildfind
Peter Otten <[EMAIL PROTECTED]> writes:
> > while not usrinp.lower() in "yn":
>
> But note that 'in' performs a substring search and therefore "yn" and ""
> would be accepted as valid answers, too.
Oh right, that's a recent change to the language, I think. OK:
while not usrinp.lower() in list
On 25/01/07, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> Peter Otten a écrit :
> > Bruno Desthuilliers wrote:
> >
> >> and simplified again thanks to Python 'in' operator:
> >> while not usrinp.lower() in "yn":
> >
> > But note that 'in' performs a substring search and therefore "yn" and ""
>
Peter Otten a écrit :
> Bruno Desthuilliers wrote:
>
>> and simplified again thanks to Python 'in' operator:
>> while not usrinp.lower() in "yn":
>
> But note that 'in' performs a substring search and therefore "yn" and ""
> would be accepted as valid answers, too.
Mmm, right. Thanks for the cor
Bruno Desthuilliers wrote:
> and simplified again thanks to Python 'in' operator:
> while not usrinp.lower() in "yn":
But note that 'in' performs a substring search and therefore "yn" and ""
would be accepted as valid answers, too.
Peter
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] writes:
> while usrinp != "y" or "Y" or "N" or "n": PROBLEM
while userinp not in 'yYnN':
...
Or maybe more generally:
while userinp.lower() not in 'yn':# case independent test
...
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] a écrit :
> Hmm, my while loop with "or" doesn't seem to work as I want it to...
> How do I tell the while loop to only accept "Y" or "y" or "N" or "n"
> input from the str(raw_input)?
>
> Thank's in advance!
>
> Snippet of code:
>
> import os
>
> def buildfinder():
> os.s
> while usrinp != "y" or "Y" or "N" or "n": PROBLEM
Correct way:
while usrinp != "y" or usrinp != "Y" or usrinp != "N" or usrinp != "n":
There has to be a boolean evaluation on both sides of or.
Or in this case:
while usrinp not in ['Y', 'y', 'N', 'n']:
Ravi Teja.
--
http://mail.p
Hmm, my while loop with "or" doesn't seem to work as I want it to...
How do I tell the while loop to only accept "Y" or "y" or "N" or "n"
input from the str(raw_input)?
Thank's in advance!
Snippet of code:
import os
def buildfinder():
os.system("CLS")
GameRoot = os.getenv("GAME_ROOT") +
11 matches
Mail list logo