[Tutor] if syntax expression help

Alan Gauld alan.gauld at btinternet.com
Thu Nov 25 23:23:09 CET 2010


"Rance Hall" <ranceh at gmail.com> wrote


> My current if statement looks like this:
>
>            if ((userentry.lower != "c" or userentry.lower != "i") 
> and
>                 mode == "add"):

Peter has poinrted out one roblem but there is another.

The or expression will always be true, consider:
1) The first term will only fail if the value is 'c'
If the value is 'c; then the second trrrm will be True
and the or expression will be True
2)The 2nd term will only fail if the value is 'i'
If the value is 'i' then the first term will be True
and the or expression will be True

And since True and A is the same as A you ight as well
just write:

if mode == 'add':

Based on your code I'm not actually sure what the correct logic
should be, but I'm pretty sure its not what you have!


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list