{"id":25674,"date":"2021-12-04T09:19:10","date_gmt":"2021-12-04T03:49:10","guid":{"rendered":"https:\/\/python-programs.com\/?p=25674"},"modified":"2021-12-04T09:19:10","modified_gmt":"2021-12-04T03:49:10","slug":"finding-quadrant-from-x-and-y-values-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/finding-quadrant-from-x-and-y-values-python\/","title":{"rendered":"Finding Quadrant from x and y values – Python"},"content":{"rendered":"
Hello, programmer! Today, in this tutorial, we will do some basic coding in Python to find which quadrant of the s a specific point belongs to in space.<\/p>\n
In 2D space, there are a total of four coordinates.<\/p>\n
The condition for each quadrant, in this case, is as follows:<\/p>\n
Quadrant 1:<\/strong> negative x and a positive y. Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" Hello, programmer! Today, in this tutorial, we will do some basic coding in Python to find which quadrant of the s a specific point belongs to in space. In 2D space, there are a total of four coordinates. The condition for each quadrant, in this case, is as follows: Quadrant 1: negative x and a …<\/p>\n
\nQuadrant 2:<\/strong>\u00a0 x and y are both positive.
\nQuadrant 3:<\/strong>\u00a0 x and y are both negative.
\nQuadrant 4:<\/strong> positive x and a negative y.<\/p>\nFinding Quadrant from x and y values – Python<\/h2>\n
\n
Method #1: Using If-Else Conditional Statements (Static Input)<\/h3>\n
\n
# Give the x-coordinate as static input and store it in a variable.\r\nx_coordinate = 6\r\n# Give the y-coordinate as static input and store it in another variable.\r\ny_coordinate = -2\r\n# Check if the given x-coordinate is less than 0 and y-coordinate is less than 0\r\n# using the if conditional statement.\r\nif(x_coordinate < 0 and y_coordinate < 0):\r\n # If it is true, then print \"The point is in 3rd Quadrant\".\r\n print(\"The point is in 3rd Quadrant\")\r\n# Check if the given x-coordinate is less than 0 and y-coordinate is greater\r\n# than 0 using the if conditional statement.\r\nelif(x_coordinate < 0 and y_coordinate > 0):\r\n # If it is true, then print \"The point is in 1st Quadrant\".\r\n print(\"The point is in 1st Quadrant\")\r\n# Check if the given x-coordinate is greater than 0 and y-coordinate is greater\r\n# than 0 using the if conditional statement.\r\nelif(x_coordinate > 0 and y_coordinate > 0):\r\n # If it is true, then print \"The point is in 2nd Quadrant\".\r\n print(\"The point is in 2nd Quadrant\")\r\n# Else print \"The point is in 4th Quadrant\".\r\nelse:\r\n print(\"The point is in 4th Quadrant\")\r\n<\/pre>\n
The point is in 4th Quadrant<\/pre>\n
Method #2: Using If-Else Conditional Statements (User Input)<\/h3>\n
\n
# Give the x-coordinate as user input using the int(input()) function and store it in a variable.\r\nx_coordinate = int(input(\"Enter x coordinate = \"))\r\n# Give the y-coordinate as user input using the int(input()) function and store it in another variable.\r\ny_coordinate = int(input(\"Enter x coordinate = \"))\r\n# Check if the given x-coordinate is less than 0 and y-coordinate is less than 0\r\n# using the if conditional statement.\r\nif(x_coordinate < 0 and y_coordinate < 0):\r\n # If it is true, then print \"The point is in 3rd Quadrant\".\r\n print(\"The point is in 3rd Quadrant\")\r\n# Check if the given x-coordinate is less than 0 and y-coordinate is greater\r\n# than 0 using the if conditional statement.\r\nelif(x_coordinate < 0 and y_coordinate > 0):\r\n # If it is true, then print \"The point is in 1st Quadrant\".\r\n print(\"The point is in 1st Quadrant\")\r\n# Check if the given x-coordinate is greater than 0 and y-coordinate is greater\r\n# than 0 using the if conditional statement.\r\nelif(x_coordinate > 0 and y_coordinate > 0):\r\n # If it is true, then print \"The point is in 2nd Quadrant\".\r\n print(\"The point is in 2nd Quadrant\")\r\n# Else print \"The point is in 4th Quadrant\".\r\nelse:\r\n print(\"The point is in 4th Quadrant\")\r\n<\/pre>\n
Enter x coordinate = -4\r\nEnter x coordinate = -2\r\nThe point is in 3rd Quadrant<\/pre>\n