Python program to find out the quadrant in which the given co-ordinate lie
Quadrant in which the given co-ordinate lie in Python
Here, in this page we will discuss the program to find the quadrant in which the given co-ordinate lie in python . From the origin at x = 0 and y = 0, a pointy can move in four different directions. There are 4 coordinates available when we think in 2-Dimension. These 2-dimensions are at X-axis and Y-axis. Now based on their positive or negative nature this axis shows 4 different quadrants. This 4-Quadrants are different and are as follows.
Working :
According mathematics quadrants rules:
- X is positive integer as well as Y is also positive a integer it signifies first quadrant.
- X is negative integer but Y is positive integer it signifies second quadrant.
- X is negative integer as well as Y is also negative integer it signifies third quadrant.
- X is positive integer but Y is negative integer it signifies fourth quadrant.
Algorithm :
- Get value of x & y
- If ( x>0 and y>0 ) First Quadrant
- If ( x<0 and y>0 ) Second Quadrant
- If ( x<0 and y<0 ) Third Quadrant
- If ( x>0 and y>0 ) Fourth Quadrant
- If ( x=0 and y=0 ) Origin
- If ( x!=0 and y=0 ) x-axis
- If ( x>0 and y>0 ) y-axis
Python code
Run
# for initialization of coordinates
x, y = map(int, list(input("Insert the value for variable X and Y : ").split(" ")))
# find true condition of first quadrant
if x > 0 and y > 0:
print("point (", x, ",", y, ") lies in the First quadrant")
# find second quadrant
elif x < 0 and y > 0:
print("point (", x, ",", y, ") lies in the Second quadrant")
# To find third quadrant
elif x < 0 and y < 0:
print("point (", x, ",", y, ") lies in the Third quadrant")
# To find Fourth quadrant
elif x > 0 and y < 0:
print("point (", x, ",", y, ") lies in the Fourth quadrant")
# To find does not lie on origin
elif x == 0 and y == 0:
print("point (", x, ",", y, ") lies at the origin")
# On x-axis
elif y == 0 and x != 0:
print("point (", x, ",", y, ") on x-axis")
# On y-axis
elif x == 0 and y != 0:
print("point (", x, ",", y, ") on at y-axis")
Output
Insert the value for variable X and Y : -3 -33 point (-3, -33) lies in the Third quadrant
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Login/Signup to comment

x, y = map(int, list(input(“Insert the value for variable x and y :”).split(” “)))
if (x==0 or y ==0):# for origin and axis checks if any of the condition is true
if (x==0 and y == 0):
print(“Origin”)
elif (x!=0 and y == 0):
print(“X-axis”)
elif (x ==0 and y != 0):
print(“Y-axis”)
elif (x>0 and y>0): # for all quadrants where the no is more than zero
print(“First Quadrant”)
elif (x0):
print(“Second Quadrant”)
elif (x<0 and y0 and y<0):
print("Fourth Quadrant")
x=int(input(“Enter the x-coordinate “))
y=int(input(“Enter the y-coordinate “))
if x==0 and y==0:
print(“({},{}) lies on the origin”.format(x,y))
elif x==0:
print(“({},{}) lies on the y-axis”.format(x,y))
elif y==0:
print(“({},{}) lies on the x-axis”.format(x,y))
elif x>0 and y>0:
print(“({},{}) lies in the 1st quadrant”.format(x,y))
elif x0:
print(“({},{}) lies on the 2nd quadrant”.format(x,y))
elif x<0 and y0 and y<0:
print("({},{}) lies on the 4th quadrant".format(x,y))
//java program to find Quadrant lie
import java.util.Scanner;
public class Main{
public static void main(String [] args)
{
Scanner input=new Scanner(System.in);
System.out.println(” Enter the value of X;”);
int x=input.nextInt();
System.out.println(“Enter the value of Y:”);
int y=input.nextInt();
if(x>0&&y>0)
{
System.out.println(“The number lies in first quadrants:”);
}
else if(x0)
{
System.out.println(“The number lies in 2nd quadrants:”);
}
else if(x<0&&y0&&y<0)
{
System.out.println("The number lies in 4th quadrants:");
}
}
}