I am wondering why it returns True:
if False or True and True == True and (False == True or False == (not True)) or False and False and True:
pass
doesn't it accept "and False" part in the end as False? doesn't all statements with "and" return True?
CodePudding user response:
Starting with:
False or True and True == True and (False == True or False == (not True)) or False and False and True
Solve parentheses first:
(False == True or False == (not True))
Solve parentheses first - not True
is False
:
(False == True or False == False)
Next order of operation: ==
:
((False == True) or (False == False))
Resulting in:
((False) or (True))
Next order of operation: or
:
(True)
Now we have:
False or True and True == True and (True) or False and False and True
Next order of operation: ==
:
False or True and (True == True) and True or False and False and True
Resulting in:
False or True and (True) and True or False and False and True
Next order of operation: and
:
False or ((True and True) and True) or ((False and False) and True)
Resulting in:
False or ((True) and True) or ((False) and True)
And then:
False or (True) or (False)
Now the or
operator:
((False or True) or False)
And then:
((True) or False)
Which results in True
because True or False
is True
.