[Tutor] if syntax expression help
ranceh at gmail.com
Thu Nov 25 22:33:24 CET 2010
I have a user entered variable that I need to check to see if they
entered one of the two legal values.
But I only need to check this if one other fact is true.
we have a variable called "mode" whose value is either "add" or
"edit" based on how we where called.
we have a userentry variable tied to an imput function.
My current if statement looks like this:
if ((userentry.lower != "c" or userentry.lower != "i") and
mode == "add"):
do other stuff
My problem is that my other stuff always executes even when I think my
stuff should run.
so what I want is two conditions tested simultaneously
I think I have a syntax problem with the parenthesis because I can't
find documentation where this is valid, but it doesn't error out so
python doesn't choke on this.
I know about nested ifs but I was trying to avoid them for elegance
and easier reading.
if mode is "add" then my userentry field needs good data, but if my
mode is NOT "add" then I don't care about this data cause I'm not
going to be using it.
Ive tried to construct the logic such that when the if is true, its
the stuff that runs, and when the if is false, its the other stuff
Because of the NOT equal tos in the if a false is actually a passed
test, and true is actually a failed test.
Could someone please help me figure out the best way to say this in python.
BTW its python31
More information about the Tutor