Multiple Logical Comparisons On A Single Line For An If Statement
I want to do multiple comparisons for a logical condition in python but I am not sure of the right way round for the and and or. I have 2 statements. Statement 1: #if PAB is more
Solution 1:
Looking at statement 1, I'm assuming you mean:
if (PAB > BAC and PAB< PAC) or (PAB > BAC and PAC>BAC):
In which case, I'd probably write it like this (using chained comparisons, docs: python2, python3):
if (BAC < PAB < PAC) or min(PAB,PAC)>BAC:
You can use an analogous form for statement 2.
Having said that, I cannot make your comments in the question's code match up with my interpretation of your conditionals, so it's plausible I don't understand your requirement.
Post a Comment for "Multiple Logical Comparisons On A Single Line For An If Statement"