Problem I have with a while loop/boolean/or

gslindstrom at gslindstrom at
Wed Mar 14 15:56:55 CET 2007

On Mar 13, 5:34 pm, "israph... at"
<israph... at> wrote:
> Hi all.
> I have a problem with some code :(
> -----------
> hint = raw_input("\nAre you stuck? y/n: ")
> hint = hint.lower()
> while (hint != 'n') or (hint != 'y'):
>     hint = raw_input("Please specify a valid choice: ")

I'd even make it a little more bullet-proof by using lower()

while hint.lower() not in ('y','n'):

That way if the user types in 'Y' on 'N' it will still work.  I've
even gone further on occasion

while hint.lower()[0] not in ('y','n'):

so if they type 'Yes' or 'No' you're still good.


More information about the Python-list mailing list