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

Point Location on Axes

Identify the origin and coordinate axes with Python conditions. Students learn why the most specific zero-coordinate case belongs before the broader axis tests.

AdvancedPhase 1 - Level 5: Creative / Tricky Logical ScenariosExample 1 of 10
point-location-on-axes.py
1# Take coordinates
2x = float(input("Enter x coordinate: "))
3y = float(input("Enter y coordinate: "))
4
5# Check location
6if x == 0 and y == 0:
7 print("At origin")
8elif x == 0:
9 print("On Y-axis")
10elif y == 0:
11 print("On X-axis")
12else:
13 print("Not on any axis")

Output

Enter x coordinate: 0
Enter y coordinate: 0
At origin

Enter x coordinate: 0
Enter y coordinate: 5
On Y-axis

Enter x coordinate: 3
Enter y coordinate: 0
On X-axis

In this one

  • Prioritize a specific case
  • Understand coordinate axes
  • Cover off-axis points

How it works

  1. 1

    Read x and y.

  2. 2

    Check both zero before checking either zero alone.

  3. 3

    Print origin, the relevant axis, or neither.

Edge cases

Where is (0, 5)?

Where is (0, 5)?

On the Y-axis, since x is zero.

Where is (0, 0)?

Where is (0, 0)?

At origin, caught before either broader axis case.

What's going on

The origin satisfies both axis conditions, so it must be tested first. The program reads x and y as floating-point coordinates and checks whether both are zero.

If only x is zero, the point lies on the Y-axis. If only y is zero, it lies on the X-axis. A point with neither zero is off both axes; this program does not name its quadrant.

Where is (0, 5)? On the Y-axis, since x is zero.

Where is (0, 0)? At origin, caught before either broader axis case.

Quiz

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

Question 1

Why test the origin first?

Pick an answer to check it.

Question 2

Where is (0, 5)?

Pick an answer to check it.

Questions people ask

Where is (0, 5)?

On the Y-axis, since x is zero.

Where is (0, 0)?

At origin, caught before either broader axis case.

Why test the origin first?

It would also satisfy the individual axis tests.