Find the Quadrant from x and y values in Python

Feature Img Quadrant

Hey coder! Today in this tutorial we will do a simple basic coding in Python programming to determine that a particular point belongs to which quadrant in the space.

We all know there are in total 4 coordinates in the 2D space as shown in the image below.


Here the condition for each quadrant is as follows:

  1. Quadrant 1: x is negative and y is positive
  2. Quadrant 2: Both x and y are positive
  3. Quadrant 3: Both x and y are negative
  4. Quadrant 4: x is positive and y is negative

Now let’s look at the code implementation of quadrant determination in which we simply need to check the value of the x and y value of a point in the space.

Finding the Quardrant Based on X,Y Position

x = int(input())
y = int(input())

if(x<0 and y<0):
    print(" belongs to 3rd Quadrant.")
elif(x<0 and y>0):
    print(" belongs to 1st Quadrant.")
elif(x>0 and y>0):
    print(" belongs to 2nd Quadrant.")
    print(" belongs to 4th Quadrant.")

Some sample outputs of the code are displayed below. Have a look and cross-check the outputs if you want.

( 2 , -3 ) belongs to 4th Quadrant.
( 2 , 4 ) belongs to 2nd Quadrant.

I hope the logic of the quadrants and allocation of quadrants to points in space. Thank you for reading the tutorial!

Happy Learning! 😇