0

I'm trying to make this statement to evaluate to be true using parentheses. I have tried multiple combinations but it always evaluates out to be false

2 + 3 == 4 + 5 == 7

Owen Hope
  • 9
  • 1

1 Answers1

4

False is considered to be 0, and True is considered to be 1, so it should be:

(2 + (3 == 4) + 5) == 7

Since False is 0, the 3 == 4 part would evaluate to 0. Because of this, the expression would be the equivalent of:

(2 + 0 + 5) == 7

which would evaluate to True

Leejay Schmidt
  • 1,193
  • 1
  • 15
  • 24
  • 1
    Note that this only works properly in Python 3.x. See for instance [here](http://stackoverflow.com/a/2764099/5717099). – morido Jan 25 '16 at 22:27
  • There should be no problem in Python 2. Even overriding the built-in `False`: `__builtins__.False = 10;print int(3 == 4);print False` gives a zero for the comparison. Prints: `0` and `10`. – Mike Müller Jan 25 '16 at 22:55
  • Thanks @MikeMüller. Upon further testing, I got the same results (removed the disclaimer since it seems this won't be an issue) – Leejay Schmidt Jan 25 '16 at 23:00