Write a program that prompts the user to input the x-y coordinate of a point in a Cartesian plane. The program should then output a message indicating whether the point is the origin, is located on the x- (or y-) axis, or appears in a particular quadrant.
Samples of expected output:
Enter x and y coordinates: 0 0
(0, 0) is the origin
Enter x and y coordinates: 4 0
(4, 0) is on the x-axis
Enter x and y coordinates: 0 -3
(0, -3) is on the y-axis
Enter x and y coordinates: -2 3
(-2, 3) is in the second quadrant
Enter x and y coordinates: 1 -4
(-2, 3) is in the fourth quadrant
xy=input("Enterthe x-y coordinate of a point in a Cartesian plane. ").split(' ')
x=int(xy[0])
y=int(xy[1])
if x == 0 and y == 0:
print(f"({x},{y}) is the origin")
elif y == 0:
print(f"({x},{y}) is on the x-axis")
elif x == 0:
print(f"({x},{y}) is on the y-axis")
elif y > 0:
if x > 0:
print(f"({x},{y}) is in the first quadrant")
else:
print(f"({x},{y}) is in the second quadrant")
else:
if x < 0:
print(f"({x},{y}) is in the third quadrant")
else:
print(f"({x},{y}) is in the fourth quadrant")
Comments
Leave a comment