Quadrants in which a given coordinate lies
Learn how to solve the 'Quadrants in which a given coordinate lies' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
Write a function find_quadrant(x, y) that takes two integers x and y representing a point on the Cartesian plane and returns a string indicating which quadrant the point lies in.
Return:
- 'Quadrant 1' if x > 0 and y > 0
- 'Quadrant 2' if x < 0 and y > 0
- 'Quadrant 3' if x < 0 and y < 0
- 'Quadrant 4' if x > 0 and y < 0
- 'Origin' if x == 0 and y == 0
- 'X-Axis' if y == 0 and x != 0
- 'Y-Axis' if x == 0 and y != 0
- •-10^4 <= x, y <= 10^4
Examples
find_quadrant(3, 5)
'Quadrant 1'
Both x=3 and y=5 are positive, so the point is in Quadrant 1 (upper-right).
find_quadrant(-2, 4)
'Quadrant 2'
x=-2 is negative and y=4 is positive, so the point is in Quadrant 2 (upper-left).
find_quadrant(-1, -7)
'Quadrant 3'
Both x=-1 and y=-7 are negative, so the point is in Quadrant 3 (lower-left).
Need a Hint?
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.