Exercises · Q4
Q.Add a pair of parentheses to each expression so that it evaluates to True.
a) 0 == 1 == 2
b) 2 + 3 == 4 + 5 == 7
c) 1 < -1 == 3 > 4
Yanam CbseNCERTSubjective· 3mImportance★★★★★est
63% · 31/49 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →The trick is that Python's booleans are numbers (False == 0, True == 1): parenthesise an inner comparison so its False/True takes part in the outer arithmetic/comparison — a) 0 == (1 == 2), b) 2 + (3 == 4) + 5 == 7, c) (1 < -1) == (3 > 4).
The idea. Without parentheses these are chained comparisons (0 == 1 == 2 means 0 == 1 and 1 == 2) and all evaluate to False. Parentheses break the chain, and because bool is a subclass of int (False == 0, True == 1), the inner result can be compared or added numerically.
a) 0 == (1 == 2)
| Step | Expression | Value |
|---|---|---|
| 1 | 1 == 2 | False |
| 2 | 0 == False | True (False equals 0) |
b) 2 + (3 == 4) + 5 == 7
| Step | Expression | Value |
|---|---|---|
| 1 | 3 == 4 | False (numerically 0) |
| 2 | 2 + 0 + 5 | 7 |
| 3 | 7 == 7 | True |
c) (1 < -1) == (3 > 4)
| Step | Expression | Value |
|---|---|---|
| 1 | 1 < -1 | False |
| 2 | 3 > 4 | False |
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.