While loop with "or"? Please help!
wittempj@hotmail.com
martin.witte at gmail.com
Thu Jan 25 08:10:32 EST 2007
On Jan 25, 11:26 am, wd.jons... at gmail.com 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 buildfinder():
> os.system("CLS")
> GameRoot = os.getenv("GAME_ROOT") + "\\"
>
> print "Do you want to use " + GameRoot + " as your source
> directory?"
> usr = str(raw_input('Y/N: '))
> return usr
>
> #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_input('Y/N: '))
> else:
> code continues
also note that your naming of variables contains two different names
for one variable...
better
usrinp = ''
while usrinp.lower() not in ('y', 'n'):
usrinp = raw_input('Y/N: ') # and not usr....
More information about the Python-list
mailing list