A point identified by the co-ordinates x,y is in one of the four quadrants of the co-ordinate system. Let’s write a Python program to find the quadrant of a point specified by x,y.
How many quadrants are there in a plane?
There are 4 quadrants in a plane in the co-ordinate system. A point x,y belongs to one of the four quadrants. The quadrant is determined by the values of x and y.
- Quadrant 1: The x co-ordinate is positive and the y co-ordinate is positive.
- Quadrant 2: The x co-ordinate is negative and the y co-ordinate is positive.
- Quadrant 3: The x co-ordinate is negative and the y co-ordinate is negative.
- Quadrant 4: The x co-ordinate is positive and the y co-ordinate is negative.
If x co-ordinate and y co-ordinate are both equal to 0, then it indicates the Origin point.
How to determine the quadrant of a point?
A Python program with an if-elif conditional statement can be used to determine the quadrant of the point.
Python code (to determine the quadrant)
#Program to find the quadrant of a point
x = int(input("Enter the x co-ordinate "))
y = int(input("Enter the y co-ordinate "))
if x>0 and y>0:
print("Point is in First Quadrant")
elif x<0 and y>0:
print("Point is in Second Quadrant")
elif x<0 and y<0:
print("Point is in Third Quadrant")
elif x>0 and y<0:
print("Point is in Fourth Quadrant")
else:
print("Point is the Origin")
Python code (to determine quadrant using function)
The code to determine the quadrant of a point x,y can be written using a function, which returns the quadrant number of the given point.
#Function to find the quadrant of a point
def getQuadrant(x, y):
if x>0 and y>0:
return 1
elif x<0 and y>0:
return 2
elif x<0 and y<0:
return 3
elif x>0 and y<0:
return 4
else:
return 0
#code to test the above function
x = int(input("Enter the x co-ordinate "))
y = int(input("Enter the y co-ordinate "))
print("The quadrant is ", getQuadrant(x, y))