Point’s Quadrant Locator

Tags: If-Else

Write a program that reads the coordinates of a point (x, y) and determines in which quadrant the point lies.

Example 1:

Input: (3, 4)

Output: "Quadrant 1"

Example 2:

Input: (-3, -4)

Output: "Quadrant 3"

Remember, if both x and y are positive, the point lies in the first quadrant.

def find_quadrant(coords):
x, y = coords
if x > 0 and y > 0:
return “Quadrant 1”
elif x < 0 and y > 0:
return “Quadrant 2”
elif x < 0 and y < 0:
return “Quadrant 3”
elif x > 0 and y < 0:
return “Quadrant 4”
else:
return “On an axis”

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!