Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

Determine Quadrant

Locate a point in a quadrant, on an axis, or at the origin. Students trace Python sign comparisons and see why zero coordinates need separate branches.

IntermediatePhase 1 - Level 3: Math and Number LogicExample 6 of 10
determine-quadrant.py
1# Take coordinates
2x = float(input("Enter x coordinate: "))
3y = float(input("Enter y coordinate: "))
4
5# Determine quadrant
6if x > 0 and y > 0:
7 print("Quadrant I")
8elif x < 0 and y > 0:
9 print("Quadrant II")
10elif x < 0 and y < 0:
11 print("Quadrant III")
12elif x > 0 and y < 0:
13 print("Quadrant IV")
14elif x == 0 and y == 0:
15 print("Origin")
16elif x == 0:
17 print("On Y-axis")
18else:
19 print("On X-axis")

Output

Enter x coordinate: 3
Enter y coordinate: 4
Quadrant I

Enter x coordinate: -2
Enter y coordinate: 5
Quadrant II

In this one

  • Read coordinate signs
  • Distinguish axes and quadrants
  • Handle the origin first

How it works

  1. 1

    Read x and y as floats.

  2. 2

    Try the four nonzero sign combinations.

  3. 3

    Then distinguish origin, Y-axis, and X-axis.

Edge cases

Where is (-2, 5)?

Where is (-2, 5)?

Quadrant II: x is negative and y is positive.

Where is (0, 0)?

Where is (0, 0)?

Origin; its special branch comes before the axis branches.

What's going on

A quadrant depends on both coordinate signs. Four and conditions cover the four nonzero sign combinations in counterclockwise order, starting with positive x and positive y.

If none matches, at least one coordinate is zero. The origin is tested before either single-axis case so (0, 0) gets its own label. Otherwise x equal to zero means the Y-axis; the remaining case is the X-axis.

Where is (-2, 5)? Quadrant II: x is negative and y is positive.

Where is (0, 0)? Origin; its special branch comes before the axis branches.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

What places a point on the Y-axis?

Pick an answer to check it.

Question 2

Where is (-2, 5)?

Pick an answer to check it.

Questions people ask

Where is (-2, 5)?

Quadrant II: x is negative and y is positive.

Where is (0, 0)?

Origin; its special branch comes before the axis branches.

What places a point on the Y-axis?

x == 0.