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) + \\
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.
--
[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.system(CLS)
[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
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
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 correction.
=
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
would be accepted as
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(yn): ...
--
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 buildfinder():
[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_input('Y/N: '))
else:
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:
import os
11 matches
Mail list logo