Point Location on Axes

Take coordinates (x, y) and check if the point lies on the X-axis, Y-axis, or at the origin.

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

What's going on

Check for zero coordinates to determine axis location.

Key Concepts:

Origin: both x and y are 0
Y-axis: x is 0, y is not 0
X-axis: y is 0, x is not 0
Check origin first, then axes