Program to find the Quadrant of a point

posted on 12 May 2026 , updated on 12 May 2026
geometry

Coordinate geometry is a fascinating way to map mathematical logic to visual space. A classic beginner program in Python involves taking the X and Y coordinates of a point and determining which "Quadrant" (section) of the Cartesian plane it belongs to. This is an excellent exercise for mastering if-elif-else conditional logic and understanding edge cases.

1. Conceptual Understanding: The Cartesian Plane

A Cartesian coordinate system is defined by two perpendicular lines: the horizontal X-axis and the vertical Y-axis. These axes intersect at a central point called the Origin (0, 0). These lines divide the plane into four distinct regions, known as quadrants.

The Four Quadrants and their Rules:

  • Quadrant I (Top-Right): Both X and Y are positive (X > 0, Y > 0).
  • Quadrant II (Top-Left): X is negative, Y is positive (X < 0, Y > 0).
  • Quadrant III (Bottom-Left): Both X and Y are negative (X < 0, Y < 0).
  • Quadrant IV (Bottom-Right): X is positive, Y is negative (X > 0, Y < 0).

2. Implementation: The Pythonic Way

To write this program, we use a chain of if-elif-else statements to systematically check the positive and negative states of the input coordinates. We use float() to ensure our program can handle decimal values (like 2.5 or -3.14), not just integers.

# Python Program to find the Quadrant of a Point

def find_quadrant(x, y):
    # Check the standard four quadrants
    if x > 0 and y > 0:
        return "in Quadrant I"
    elif x < 0 and y > 0:
        return "in Quadrant II"
    elif x < 0 and y < 0:
        return "in Quadrant III"
    elif x > 0 and y < 0:
        return "in Quadrant IV"
        
    # Handle the Edge Cases (Lying on the axes or origin)
    elif x == 0 and y != 0:
        return "on the Y-axis"
    elif y == 0 and x != 0:
        return "on the X-axis"
    else:
        # If it's not in a quadrant and not on an axis, it MUST be the origin
        return "at the Origin"

# Take input from the user
try:
    x_coord = float(input("Enter the X coordinate: "))
    y_coord = float(input("Enter the Y coordinate: "))
    
    # Call the function and print the result
    position = find_quadrant(x_coord, y_coord)
    print(f"The point ({x_coord}, {y_coord}) lies {position}.")
    
except ValueError:
    print("Invalid input! Please enter numerical values.")

3. The Importance of Edge Cases

Notice the second half of our if-elif logic. A very common mistake for beginners is assuming a point must fall into one of the four quadrants. But what if the user inputs (0, 5)? This point isn't in a quadrant; it lies directly on the Y-axis!

💡 Pro-Tip on Logic Order:
When writing long conditional chains, always think about mutual exclusivity. Because we checked all cases where X and Y are non-zero first, by the time we reach the final else: statement, we mathematically know that both X and Y must equal 0. We don't even need to write elif x == 0 and y == 0:, saving us computation time!

💡 Mind-Blowing Facts About Coordinate Geometry

  • A Fly on the Ceiling: The Cartesian coordinate system was invented by the French mathematician and philosopher René Descartes in the 17th century. Legend has it that he came up with the idea while lying in bed, watching a fly crawl across the ceiling, and realizing he could describe its exact position using its distance from two intersecting walls.
  • Bridging Two Worlds: Before Descartes, Algebra and Geometry were considered two completely separate fields of mathematics. The invention of the coordinate plane allowed geometric shapes to be defined by algebraic equations (like defining a circle as x2 + y2 = r2) for the very first time!
  • Beyond 2D: While we learn about 4 quadrants in 2D space, 3D space (using X, Y, and Z axes) is divided into 8 regions, which are called Octants!

Interactive Quadrant Explorer

Point (3, 4) is in Quadrant I

Related Programs

...

A Python program to find the Distance between two points in Co-ordinate geometry.

...

A Python program to find the Distance of a Point from the Origin in Co-ordinate geometry.

...

A Python program to find the Quadrant of a Point in Co-ordinate geometry.

Search
Download PYTHON
Download Python on your system from python.org downloads section