
Problem
Solution
Submissions
Chain Comparison Operators
Certification: Basic Level
Accuracy: 33.19%
Submissions: 238
Points: 5
Write a Python program to chain multiple comparison operators.
Example 1
- Input: a = 5, b = 10, c = 15
- Output:
- a < b < c → True
- a > b < c → False
- Explanation:
- Step 1: For a < b < c, check if a < b (5 < 10) and b < c (10 < 15).
- Step 2: Since both conditions are True, the result is True.
- Step 3: For a > b < c, check if a > b (5 > 10) and b < c (10 < 15).
- Step 4: Since a > b is False, the entire expression evaluates to False.
Example 2
- Input: x = 100, y = 200, z = 300
- Output:
- x < y < z → True
- x > y > z → False
- Explanation:
- Step 1: For x < y < z, check if x < y (100 < 200) and y < z (200 < 300).
- Step 2: Since both conditions are True, the result is True.
- Step 3: For x > y > z, check if x > y (100 > 200) and y > z (200 > 300).
- Step 4: Since both x > y and y > z are False, the entire expression evaluates to False.
Constraints
- -10^6 ≤ value ≤ 10^6 for each variable
- All input values are integers
- Maximum chain length: 5 comparisons
- Time Complexity: O(1)
- Space Complexity: O(1)
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Chain comparisons automatically use logical AND
- Python evaluates chains from left to right