Back to Practice Dashboard
Python BasicsEasy

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

Easy

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

Constraints
  • -10^4 <= x, y <= 10^4

Examples

Example 1
Input
find_quadrant(3, 5)
Output
'Quadrant 1'
Explanation

Both x=3 and y=5 are positive, so the point is in Quadrant 1 (upper-right).

Example 2
Input
find_quadrant(-2, 4)
Output
'Quadrant 2'
Explanation

x=-2 is negative and y=4 is positive, so the point is in Quadrant 2 (upper-left).

Example 3
Input
find_quadrant(-1, -7)
Output
'Quadrant 3'
Explanation

Both x=-1 and y=-7 are negative, so the point is in Quadrant 3 (lower-left).

Need a Hint?
Use simple arithmetic operators (like modulo `%`, division `//`), conditional checks, or loops to inspect number properties.
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.

Open in Editor