Which is "more correct (logically)"? Specific to Leap Year, not in general.
With Parentheses
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
Without
return year % 4 == 0 and year % 100 != 0 or year % 400 == 0
Additional Info
Parentheses change the order in which the booleans are evaluated (and
goes before or
w/o parenthesis).
Given that all larger numbers are divisible by smaller numbers in this problem, it returns the correct result either way but I'm still curious.
Observe the effects of parentheses:
False and True or True #True False and (True or True) #False
False and False or True #True False and (False or True) #False
Without parentheses, there are scenarios where even though year is not divisible by 4 (first bool) it still returns True (I know that's impossible in this problem)! Isn't being divisible by 4 a MUST and therefore it's more correct to include parenthesis? Anything else I should be paying attention to here? Can someone explain the theoretical logic of not/including parentheses?