Answer to Question #178822 in Python for Woyengimiesindo Malati

Question #178822

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


1
Expert's answer
2021-04-08T14:50:57-0400
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))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS