False == (False or True) False Can someone please help explain why this comes out False? | Sololearn: Learn to code for FREE!
+ 4

False == (False or True) False Can someone please help explain why this comes out False?

10th Jul 2020, 3:17 PM
Reacy.Py
Reacy.Py - avatar
13 Answers
+ 7
It is simply boolean algebra we have (1 = true, 0 = false) OR 1 0 -> 1 0 1 -> 1 1 1 -> 1 0 0 -> 0
10th Jul 2020, 3:25 PM
Emanuel Maliaño
Emanuel Maliaño - avatar
+ 3
I didn't say I think it isn't false, I'm new to this and was asking for help as to why it's false. I just need a little clarification... I'm a little confused since it says "or"...
10th Jul 2020, 3:31 PM
Reacy.Py
Reacy.Py - avatar
+ 3
Vikash explains the reason very well. To add clarity, the == is a comparison operator. By the rule of order of operations parentheses are processed first. So the boolean expression (false or true) evaluates to True. Then the expression is evaluated as false == true. (Which reads "is false equal to true?) Which is False. Hence the result. When reading the code it's easy to make the logical error of assuming that if the left side of the comparison is false and the right side is false OR true then the result would be True. However, the order of operations and how boolean logic is processed has to be considered.
11th Jul 2020, 2:07 AM
Johann Lynge
Johann Lynge - avatar
+ 3
Fist of all false is 0 and true is 1 if 0 and 1 meet we get zero but if 1 and 1 meet we get one and if 0 and 0 meet we get 0 so this means that : false ==(false or true ) Is the same as saying. : 0 == ( 0 or 1 ) as you can see now that the can't be any possibility of having a true number since 0 and zero bring 0 and 0 and 1 bring 0 thank you hope it helps it only takes a second to upvote 😁
11th Jul 2020, 11:35 PM
Pjc
Pjc - avatar
+ 3
False == (False or True) In this expression python would first solve the comparison operator in bracket. => (False or True) is said to be True. Because the 'OR' operator search for the first truthy value, and if found it returns the value else 'False'. Now we have: =>False == True is False.
12th Jul 2020, 2:24 PM
Samuel Mathew
Samuel Mathew - avatar
+ 2
Thanks a lot, I have a much better understanding now... Special thanks to Emanuel Maliaño for breaking it down like that!
10th Jul 2020, 3:52 PM
Reacy.Py
Reacy.Py - avatar
+ 2
I appreciated Vikash as well and acknowledged Vikash in my 1st general thanks a lot. The special thanks was just because by Emanuel listing the example with the 1's & 0's like that it gave me a visual that made it a lot clearer than just the worded examples...
11th Jul 2020, 3:15 AM
Reacy.Py
Reacy.Py - avatar
+ 2
That's the full snippet from the lesson that confused me... Part of my misunderstanding is that the previous line without parenthesis returns as true, so I didn't fully grasp why the same sequence with parenthesis returned false.
11th Jul 2020, 3:27 AM
Reacy.Py
Reacy.Py - avatar
+ 2
The lessons don't give much details is the only negative of this app... They touch only the most basic of each matter, at least from what I've seen so far... Thankfully people like you guys in the community help bridge the information gaps by being so helpful!
11th Jul 2020, 3:31 AM
Reacy.Py
Reacy.Py - avatar
+ 2
Happy to help where I can! I agree, the explanations for some of the concepts is definitely lacking sometimes. Playing with code and asking questions when stuck is how I learn too!
11th Jul 2020, 10:32 AM
Johann Lynge
Johann Lynge - avatar
0
Why do you think it isn't false?
10th Jul 2020, 3:25 PM
Abhay
Abhay - avatar
0
Oh ok
10th Jul 2020, 3:36 PM
Abhay
Abhay - avatar
0
>>> False == False or True True >>> False == (False or True) False >>> (False == False) or True True Johann Lynge
11th Jul 2020, 3:25 AM
Reacy.Py
Reacy.Py - avatar