Problem I have with a while loop/boolean/or

Fabio FZero fabio.fzero at gmail.com
Wed Mar 14 14:34:20 EDT 2007


On Mar 13, 7:34 pm, "israph... at googlemail.com"
<israph... at googlemail.com> 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: ")
>
> ---------------------------------------------
>
> so everytime I run the program, and enter my choice as y or n, I'm
> told to 'Please Specify a valid Choice Again' and can't get out of the
> loop.

Why don't you try this instead:

hint = raw_input("\nAre you stuck? y/n: ")
hint = hint.lower()

while not hint in 'yn':
    hint = raw_input("Please specify a valid choice: ")

[]s
FZero




More information about the Python-list mailing list