Question 4 of 22intermediate🔧 ApplyShort Answer1 mark

Add a pair of parentheses to each expression so that it evaluates to True.

(a)

0 == 1 == 2

Answer

0 == (1 == 2)

(b)

2 + 3 == 4 + 5 == 7

Answer

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

(c)

1 < -1 == 3 > 4

Answer

(1 < -1) == (3 > 4)

Explanation

The question tests understanding of operator precedence and how parentheses can override evaluation order. In Python, comparison operators (==, <, >) have equal precedence and are evaluated left to right. Chained comparisons like 'a == b == c' are evaluated as 'a == b and b == c'. By strategically placing parentheses, we can change the evaluation order. In (a), '1 == 2' evaluates to False (which equals 0), making '0 == False' True. In (b), '3 == 4' evaluates to False (0), so '2 + 0 + 5 == 7' becomes True. In (c), both comparisons evaluate to False, and 'False == False' is True.