It's not normal, but also not the first time I see something being weird with multi conditional
if. The optimization of conditions works this way : If there's a
and and the left part is False, then the condition already failed, Python don't look further. For an
or it's the opposite, if the left part is True, then the condition already past, and Python stop here.
This mean that... but first, the "how-to" deal with problems in conditions :
What should be tried is to isolate each condition to make clear for Python what is the left part, and what is the right one ; this for each
and/
or in the condition :
Code:
if ( ( 9 < time < 14 ) and ( ls_event_school == False ) ) and ( ( todays != "Sun" ) and ( todays != "Sat" ) ):
On a side note, parenthesis have the same meaning in coding than in math. They aren't always needed, but they always explicitly separate each part of the code. So, never hesitate to overuse them, sometimes it's what make the difference between a code that works, and one that should but don't.
Then if it still don't works, try to revert what you can. By example here you've the two "!=", so you can try :
Code:
if ( ( 9 < time < 14 ) and ( ls_event_school != True ) ) and ( not todays in [ "Sun", "Sat" ] ):
Note that I changed both the condition for "ls_event_school" and "todays", but it's better to change one, the other, then both.
Side note: You can use list for things like this. Not doing it is not enough to cause the problem. Doing it shouldn't be enough to correct it. But it's still better since it reduce many conditions to a single one.
If it still don't works, the next option it to change the order of the conditions, trying to keep optimization in mind. As I see it, the more likely to happen is that you are out of school time, then out of school days, then that everything is overwrote by a school event.
So :
Code:
if ( 9 < time < 14 ) and ( not todays in [ "Sun", "Sat" ] ) and ( ls_event_school == False ):
Speaking of this, she have school only between 10 and 13 (both included) ? Isn't it "<=" instead ?
Now that I said all this, here, the fact that it works when you split it in multi
if seem to indicate that Python do a wrong optimization ; for it the left part is False when it should be True. More explicitly, my guess is that it failed to clearly identify the different parts of the condition. I don't know how it see it, but one of the possibility (which is wrong here) can be :
Code:
if ( 9 < time < 14 and ls_event_school ) == False and (todays != "Sun" and todays != "Sat"):
As human, you know what you meant when writing the condition, and it's wrote correctly. But Python is just a machine. It have complex algorithms to split lines, they works fine 99,99% of the times, but there's still the 0.01% when the said algorithms fail to understand you.
Then when you split, therefore simplify the condition, Python fall back to the right
Code:
if ( 9 < time < 14 ) and ( ls_event_school == False ):
The line being now shorter, the algorithms fall back on their feet ; it's more logical that the "== False" is part of a second condition, than the result of a single condition like above.