Confused about while statement

Georgy no.mail at available.net
Thu May 20 22:13:09 EDT 2004


h != "hello" or "goodbye"
is
(h != "hello") or "goodbye"

It's always true because even if (h != "hello") evaluates to False,
then "goodbye" is 'tested' and considered to be true.

You probably meant:
h != "hello" and h != "goodbye"
that can be written even better as:
h not in ("hello", "goodbye")

Georgy

"EAS" <eriksp at attbi.nospam.com> wrote in message news:dHcrc.86491$536.14466932 at attbi_s03...
| In theory, the following code should ask for the user to enter a value for h
| until he/she enters hello or goodbye.
|
| h = "hi"
| while h != "hello" or "goodbye":
|         h = raw_input("Value for h:")
|
| But the program keeps asking for a value no matter what I enter. Why doesn't
| it work?





More information about the Python-list mailing list