Week 3 Sample test

need clarity on below question:
What is the output of the code?
print( True and False or True and (not 10 and False) )

The output of the code will be False.

  1. Output of (True and False) is False.
  2. then 2nd condition will be check with the output of 1st condition i.e False or True and output of this is True.
  3. then parentheses condition will be check i.e. not 10 and False and output will be False.
  4. Finally output of 2nd and 3rd will be compared i.e. True and False and output of this will be False.

Order of Precedence of Logical operators is not > and > or (see link). Brackets are evaluated before any operators (remember BODMAS rule).

So,
True and False or True and (not 10 and False)
= True and False or True and (False and False)
= True and False or True and False
= False or False
= False

padhai forum3

1 Like

Hi @Shirshendranath Thanks for your response.
need more clarity on the Below logic: how do you come to this conclusion
true and true=true
true and false=false
True and False= False

These results are defined by logical operators itself.

and operation yields true if both operands are true, else false.

or operation yields true if any one of the operand is true, else false.

not operation gives logically opposite value of the only operand.

See here for more info.

2 Likes