Write a program in python 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
while True:
xy = input('Enter x and y coordinates: ')
if not xy:
break
try:
x, y = map(int,(xy.split()))
except ValueError:
print('incorrect input')
continue
if x == 0 and y == 0:
print('({},{}) is the origin'.format(x, y))
elif x == 0:
print('({},{}) is on the y-axis'.format(x, y))
elif y == 0:
print('({},{}) is on the x-axis'.format(x, y))
elif x > 0 and y > 0:
print('({},{}) is in the first quadrant'.format(x, y))
elif x < 0 and y > 0:
print('({},{}) is in the second quadrant'.format(x, y))
elif x < 0 and y < 0:
print('({},{}) is in the third quadrant'.format(x, y))
elif x > 0 and y < 0:
print('({},{}) is in the fourth quadrant'.format(x, y))
Comments
Leave a comment