Editor

Which Quadrant?

#558 · Python Basics · Beginner · 30 XP · about 4 min

The x-axis and the y-axis cut a graph into four parts called quadrants:

  • quadrant 1: x and y are both positive,
  • quadrant 2: x is negative and y is positive,
  • quadrant 3: x and y are both negative,
  • quadrant 4: x is positive and y is negative.

Write quadrant(x, y) that returns the number of the quadrant the point (x, y) is in. A point that sits on an axis, where x or y is 0, is in no quadrant: return 0 for it.

Examples

quadrant(3, 5)    # returns 1
quadrant(-2, 4)   # returns 2
quadrant(-1, -1)  # returns 3
quadrant(0, 7)    # returns 0

Note

x and y can be whole numbers or decimals.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.