Q.Write logical expressions corresponding to the following statements in Python and evaluate the expressions (assuming variables num1, num2, num3, first, middle, last are already having meaningful values):
Each statement translates into a relational/chained-comparison expression; with the natural sample values (num1=5, num2=10, num3=30, the Gandhi name parts, a 3-item stationery list) they evaluate to True, False, True, False, False.
The idea — Boolean expressions. Relational operators (<, <=, ==) return True/False; Python allows chained comparisons (a < x < b), and strings compare lexicographically by Unicode code points. Since the question says the variables "already have meaningful values", we must pick and state an assumption to evaluate:
num1, num2, num3 = 5, 10, 30
first, middle, last = 'Mohandas', 'Karamchand', 'Gandhi'
stationery = ['Paper', 'Gel Pen', 'Eraser']
The expressions and their evaluation
| Part | Expression | Evaluation | Result |
|---|---|---|---|
| a | 20 + (-10) < 12 | 10 < 12 | True |
| b | num3 <= 24 | 30 <= 24 | False |
| c | num1 < 6.75 < num2 | 5 < 6.75 and 6.75 < 10 | True |
| d | first < middle < last | 'Mohandas' < 'Karamchand' → False (short-circuits) | False |
| e | stationery == [] (or len(stationery) == 0) | 3-element list vs empty | False |
Notes
- (b) "not more than 24" = "less than or equal to 24", i.e.
num3 <= 24; equivalentlynot (num3 > 24). - (c) "6.75 is between num1 and num2" reads perfectly as the chained comparison
num1 < 6.75 < num2. - (d) "middle is larger than first and smaller than last" is
middle > first and middle < last, i.e. the chainfirst < middle < last. Lexicographically 'K' (75) < 'M' (77), so 'Karamchand' is smaller than 'Mohandas' and the expression is False. - (e) an empty-list test can also be written idiomatically as
not stationery.
String comparison is by Unicode order, not alphabet intuition: all upper-case letters sort before all lower-case ones ('Z' < 'a'). With mixed-case data that surprises people.
a) 20 + (-10) < 12 → True; b) num3 <= 24 → False; c) num1 < 6.75 < num2 → True; d) first < middle < last → False; e) stationery == [] → False (under the stated sample values).
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.