Home > Blockchain >  Why am i getting False in this boolean question
Why am i getting False in this boolean question

Time:05-16

A= True

B= True

y = not(A or B) == (not(A)) and (not(B))

print (y)

gives output as False on python.

Should it not be true (False==False)?

CodePudding user response:

you need to pay attention to order of operations in general, it is always prefferred to use paranthesis when it is ambigous in your case, it is translated as

A = True
B = True
y = (not(A or B) == (not(A))) and (not(B))

which if we follow carefully is:

y = (not(True or True) == (not(True))) and (not(True))
y = (not(True) == (False)) and (False)
y = (False == False) and (False)
y = True and False
y = False

hope this helps, and good luck on your journey

CodePudding user response:

this what you need to do to get what you wanted : y = not(A or B) == ( not(A) and not(B) )

in what you did you got not(A or B) == (not(A)) as true and after this you have true and (not(B)) and this false!

  • Related