Determining quadrant

Assume finite numeric coordinates. Return the exact labels shown in the checks, including "Negative x-axis" and "Positive y-axis" for the two axis cases not listed there.

Write a function that takes two numbers (x and y) as input representing coordinates on a 2D plane. The function should return the quadrant in which the point lies (Quadrant I, II, III, or IV), the axis on which it lies (Positive or Negative x-axis or y-axis), or “Origin” if the point is at (0, 0). Use only if statements without else.

Complete Listing 1. Save the completed code as determine_quadrant.py and run it to check the supplied assertions.

Listing 1: Starter function and checks for determine_quadrant.
def determine_quadrant(x: float, y: float) -> str:
    raise NotImplementedError("Replace this line with your code.")


# One point in each quadrant
got = determine_quadrant(3, 4)
assert got == "Quadrant I", f"(3, 4): expected 'Quadrant I', got {got!r}"

got = determine_quadrant(-3, 4)
assert got == "Quadrant II", f"(-3, 4): expected 'Quadrant II', got {got!r}"

got = determine_quadrant(-3, -4)
assert got == "Quadrant III", f"(-3, -4): expected 'Quadrant III', got {got!r}"

got = determine_quadrant(3, -4)
assert got == "Quadrant IV", f"(3, -4): expected 'Quadrant IV', got {got!r}"

# On an axis: one coordinate is zero, so the point is in no quadrant
got = determine_quadrant(3, 0)
assert got == "Positive x-axis", f"(3, 0): expected 'Positive x-axis', got {got!r}"

got = determine_quadrant(0, -4)
assert got == "Negative y-axis", f"(0, -4): expected 'Negative y-axis', got {got!r}"

# Both coordinates zero: the one case that belongs to no axis direction
got = determine_quadrant(0, 0)
assert got == "Origin", f"(0, 0): expected 'Origin', got {got!r}"

# Your case: which point is most likely to break it?
# got = determine_quadrant(___, ___)
# assert got == "___", f"(___, ___): expected '___', got {got!r}"
  • assert condition checks a Boolean condition. A true condition produces no output; a false condition raises AssertionError. For example, assert 2 + 3 == 5 passes.